-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreduce.js
More file actions
46 lines (33 loc) · 780 Bytes
/
reduce.js
File metadata and controls
46 lines (33 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// nums = [3,0,1,2];
// nums.sort((a,b) => a -b); // nlogn
// let index = 0;
// for(let i = 0; i <= nums.length; i++ ){ //O(n)
// if(nums[i] == index){
// index++;
// continue;
// }else{
// console.log(index);
// break;
// }
// }
// /**
// * sum of n[0] to n[n.length - 1]
// * sum of 0 to n.length
// */
// const currSum = nums.reduce((acc, curr) => acc + curr, 0);
// const expectedSum = (nums.length * (nums.length + 1)) / 2;
// console.log("missing number is: ", expectedSum - currSum);
// let fullString = "";
// const substring = "ab"
// const sub = substring.repeat(3);
// fullString += sub;
// console.log(fullString);
const map = {
"a": 1,
"b": 2,
"c": 3
}
for(let key in map){
// console.log(key);
console.log(map[key]);
}