Real unit test (isolation, no children render)
Calls:
- constructor
- render
| export const convertCamelCaseToSnakeCase = (str: string) => { | |
| return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`) | |
| } | |
| export const convertSnakeCaseToCamelCase = (str: string) => { | |
| return str.replace(/([-_][a-z])/g, (group) => | |
| group.toUpperCase().replace('-', '').replace('_', '') | |
| ) | |
| } |
| const fs = require('fs'); | |
| const AWS = require('aws-sdk'); | |
| // Enter copied or downloaded access id and secret here | |
| const ID = ''; | |
| const SECRET = ''; | |
| // Enter the name of the bucket that you have created here | |
| const BUCKET_NAME = 'test-bucket-1242tsr';; |
| export const toBase64 = file => new Promise((resolve, reject) => { | |
| const reader = new FileReader(); | |
| reader.onload = () => { | |
| const b64 = reader.result.replace(/^data:.+;base64,/, ''); | |
| resolve(b64) | |
| }; | |
| reader.readAsDataURL(file); | |
| reader.onerror = error => reject(error); | |
| }); |
| const filterDuplicateArr = (arr) => [...new Set(arr)]; | |
| const findSecondGreatestNum = (arr = [1,2]) => { | |
| const filteredDuplicateArr = filterDuplicateArr(arr) | |
| const firstMax = Math.max(...filteredDuplicateArr); | |
| //remove the first max from array | |
| filteredDuplicateArr.shift(filteredDuplicateArr.indexOf(firstMax)); | |
| // return the new max | |
| return Math.max(...filteredDuplicateArr); | |
| } |
| const input = [5, 2, 10, 3, 11, -1, 0]; | |
| const sortedInput = []; | |
| for (let i = 0; i < input.length; i++) { | |
| for (let j = i; j < input.length; j++) { | |
| console.log('input[i]', input[i]); | |
| console.log('input[j]', input[j]); | |
| if (input[i] > input[j]) { | |
| let tmpNum = input[i]; |
| // Hackerrank | |
| // https://www.hackerrank.com/challenges/staircase/problem | |
| function staircase(n) { | |
| for(let i = 1, j = n-1; i <= n; i++, j--){ | |
| const space = ' '.repeat(j); | |
| console.log(space+'#'.repeat(i)); | |
| } | |
| } |
| // https://www.hackerrank.com/challenges/diagonal-difference/problem | |
| // first way | |
| function diagonalDifference(arr) { | |
| let sum1 = 0; | |
| let sum2 = 0; | |
| for(let i = 0, j = arr[0].length-1; i < arr[0].length; i++, j--){ | |
| sum1 += arr[i][i]; | |
| sum2 += arr[i][j]; |
| //Input: nums = [1,3,-1,-3,5,3,6,7], and k = 3 | |
| // Output: [3,3,5,5,6,7] | |
| // Explanation: | |
| // Window position Max | |
| // --------------- ----- | |
| // [1 3 -1] -3 5 3 6 7 3 | |
| // 1 [3 -1 -3] 5 3 6 7 3 | |
| // 1 3 [-1 -3 5] 3 6 7 5 | |
| // 1 3 -1 [-3 5 3] 6 7 5 |
| var emitter = require('events').EventEmitter; | |
| function LoopProcessor(num) { | |
| var e = new emitter(); | |
| setTimeout(function () { | |
| for (var i = 1; i <= num; i++) { | |
| e.emit('BeforeProcess', i); | |