This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function flatten(obj, key_id = '') { | |
| let newObj = {}; | |
| const keyPrefix = key_id + (key_id !== '' ? '.' : ''); | |
| for(let key in obj) { | |
| if (typeof obj[key] === 'object') { | |
| newObj = Object.assign({}, newObj, flatten(obj[key], key)); | |
| } else { | |
| newObj[keyPrefix + key] = obj[key]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myWordMap = {}; | |
| function generateWordMap(arg) { | |
| // var wordMap = {}; | |
| var blacklistedWords = ['after', 'the', 'and', 'then']; | |
| var wordArr = arg.replace(/[.,:]/g, '').split(' '); | |
| var word; | |
| for(var i = 0, il = wordArr.length; i < il; i++) { | |
| word = wordArr[i].toLowerCase(); | |
| if (!blacklistedWords.includes(word)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| case authActions.AuthActionTypes.RehydrateAuthState: { | |
| let isLogged = false; | |
| const role = localStorage.getItem('role') || null; | |
| const token = localStorage.getItem('access_token'); | |
| const expires = parseInt(localStorage.getItem('expires'), 10); | |
| const now = Date.now(); | |
| if ((now < expires) && token && role) { | |
| isLogged = true; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function reverseWords(messageChars) { | |
| var word = ''; | |
| var wordStack = []; | |
| var results = []; | |
| for (var i = 0, il = messageChars.length; i < il; i++) { | |
| if (messageChars[i] !== ' ') { | |
| word += messageChars[i]; | |
| } | |
| if (messageChars[i] === ' ' || i === il - 1) { | |
| wordStack.push(word); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const karatsuba = (x, y) => { | |
| const n = Math.max(x.toString().length, y.toString().length); | |
| if(n === 1) { | |
| return x * y; | |
| } | |
| let tenpowhalfn = Math.pow(10, parseInt(n / 2)); | |
| let tenpown = Math.pow(10, 2 * parseInt(n / 2)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isMatch(text, pattern) { | |
| var truthTable = []; | |
| var textArr = text.split(''); | |
| var patternArr = pattern.split(''); | |
| function initRowArray() { | |
| var newArr = []; | |
| for(var i = 0; i <= patternArr.length + 1; i++) { | |
| newArr[i] = null; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width"> | |
| <title>JS Bin</title> | |
| </head> | |
| <body> | |
| <script id="jsbin-javascript"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| Given inputs that represent overlapping times such as | |
| [[6, 10], [7, 11], [8, 10], [11, 14], [12, 14], [15, 16]] | |
| where each pair represents [startTime, endTime] | |
| return an array that groups each time pair into an array of overlapping | |
| groups as such: | |
| [ | |
| [ | |
| [6, 10], | |
| [7, 11], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const largestRunningSum = (inputArr = []) => { | |
| let runningSum = 0; | |
| let maxSum = 0; | |
| inputArr.forEach(item => { | |
| runningSum += item; | |
| if (runningSum > 0 && runningSum > maxSum) { | |
| maxSum = runningSum; | |
| } else if (runningSum < 0) { |