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
| /** | |
| * @param {number[]} arr | |
| * @return {number} | |
| */ | |
| var findLucky = function(arr) { | |
| const countMap = arr.reduce((acc, number) => { | |
| const current = acc.get(number) || 0; | |
| acc.set(number, current + 1); | |
| return acc; | |
| }, new Map()); |
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
| /** | |
| * @param {number[]} nums | |
| * @return {void} Do not return anything, modify nums in-place instead. | |
| */ | |
| // see the `compareFn` https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort | |
| function moveZeroes(nums) { | |
| // you can pass a function to sort customising how we sort | |
| nums.sort((a, z) => { | |
| // if a is 0 we tell sort to sort a after z |
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 user = { | |
| name: 'Eshaan Mathur', | |
| age: 33, | |
| isAwesome: true, | |
| }; | |
| const feilds = (Object.keys(user) as (keyof typeof user)[]).map((key) => [key, user[key]]); | |
| console.log(feilds); |
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 sleep(ms:number) { | |
| return new Promise(resolve => setTimeout(resolve, ms)) | |
| } |
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 arr1 = [ | |
| ['name', 'id', 'age', 'weight', 'cool'], | |
| ['Susan', '3', '20', '120', true], | |
| ['John', '1', '21', '150', true], | |
| ['Bob', '2', '23', '90', false], | |
| ['Ben', '4', '20', '100', true], | |
| ]; | |
| const arr2 = [ | |
| ['name', 'id', 'height'], |