-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
28 lines (23 loc) Β· 690 Bytes
/
map.js
File metadata and controls
28 lines (23 loc) Β· 690 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
// Hazrat Ali
// University Of Scholars
const numbers = [4, 6, 8, 10];
const output2 = [];
// function doubleOld(number) {
// return number * 2;
// }
// Map js
const doubleIt = number => number * 2;
for (const number of numbers) {
const result = doubleIt(number);
output2.push(result);
}
// console.log(output2);
// 1. loop through each element
// 2. for each element call the provided function
// 3. result for each element will be stored in an array
// const output = numbers.map(doubleIt);
// const output = numbers.map(number => number * 2);
const output = numbers.map(x => x * 2);
// console.log(output);
const squares = numbers.map(x => x * x);
console.log(squares);