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 frequencySort = function(s) { | |
| var arr = s.split(''); | |
| var obj = {}; | |
| var results = []; | |
| for (var i = 0; i < arr.length; i++) { | |
| obj[arr[i]] = 0 | |
| } | |
| for (var j = 0; j < arr.length; j++) { | |
| if (obj[arr[j]] !== undefined) { | |
| obj[arr[j]]++; |
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
| let messageBus = { | |
| topics: {}, | |
| subscribe: (topic, listener) => { | |
| if (!this.topics[topic]) { | |
| this.topics[topic] = [] | |
| } | |
| this.topics[topic].push(listener) | |
| }, | |
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 vowelDoubler = (array) => { | |
| for (var i = 0; i < array.length; i++) { | |
| if (array[i] === 'a' || array[i] === 'e' || array[i] === 'i' || array[i] === 'o' || array[i] === 'u') { | |
| array.splice(i, 0, array[i]) | |
| i++ | |
| } | |
| } | |
| return array; | |
| } |
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 productExceptSelf = function(nums) { | |
| //Declare a results array | |
| var results = []; | |
| //iterate through the input array | |
| for (var i = 0; i < nums.length; i++) { | |
| //Save the value in the current index in a temporary variable | |
| var current = nums[i]; | |
| //get that number out of the array | |
| nums.splice(i,1) | |
| //reduce the remaining numbers and push it into results |
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
| /** | |
| * Definition for a binary tree node. | |
| * function TreeNode(val) { | |
| * this.val = val; | |
| * this.left = this.right = null; | |
| * } | |
| */ | |
| /** | |
| * @param {TreeNode} root | |
| * @param {number} k |
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 maxEnvelopes = function(envelopes) { | |
| for (var i = 0; i < envelopes.length; i++) { | |
| for (var j = 0; j < envelopes.length - 1; j++) { | |
| if (envelopes[j][0] > envelopes[j+1][0] && envelopes[j][1] > envelopes[j+1][1]) { | |
| var temp = envelopes[j+1]; | |
| envelopes[j+1] = envelopes[j]; | |
| envelopes[j] = temp; | |
| } | |
| } | |
| } |