Skip to content

Instantly share code, notes, and snippets.

/**
* @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());
/**
* @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
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);
function sleep(ms:number) {
return new Promise(resolve => setTimeout(resolve, ms))
}
@eshaanmathur
eshaanmathur / merge-arrays.js
Last active December 12, 2020 13:16
An attempt to a solution to the problem in this video by Wes Bos https://www.youtube.com/watch?v=YGfv28PtXvA
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'],