-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathbeginner-lost-without-a-map.js
108 lines (80 loc) · 1.72 KB
/
beginner-lost-without-a-map.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function maps(numbers){
// a place to store the doubled values
const doubled = [];
// iterate over the array of numbers
for (let i = 0; i < numbers.length; i++) {
const number = numbers[i];
// double the current value and add to the doubled values array
const doubledNumber = number * 2;
doubled.push(doubledNumber);
}
// return the doubled array
return doubled;
}
function maps(numbers){
const doubled = [];
for (const number of numbers) {
const doubledNumber = number * 2;
doubled.push(doubledNumber);
}
return doubled;
}
function maps(numbers){
const doubled = [];
for (const i in numbers) {
const number = numbers[i];
const doubledNumber = number * 2;
doubled.push(doubledNumber);
}
return doubled;
}
function maps(numbers){
const doubled = [];
numbers.forEach((number) => {
const doubledNumber = number * 2;
doubled.push(doubledNumber);
});
return doubled;
}
function maps(numbers) {
const doubled = numbers.map((number) => {
const doubledNumber = number * 2;
return doubledNumber;
});
return doubled;
}
function maps(numbers) {
return numbers.map((number) => {
const doubledNumber = number * 2;
return doubledNumber;
});
}
function maps(numbers) {
return numbers.map((number) => {
return number * 2;
});
}
function maps(numbers) {
return numbers.map((number) => number * 2);
}
function maps(numbers) {
return numbers.map(number => number * 2);
}
function maps(n) {
return n.map(n=>n*2);
}
function maps(numbers) {
return 2 * numbers;
}
console.log(
maps([1, 2, 3]),
[2, 4, 6]
);
console.log(
maps([4, 1, 1, 1, 4]),
[8, 2, 2, 2, 8]
);
console.log(
maps([2, 2, 2, 2, 2, 2]),
[4, 4, 4, 4, 4, 4]
);