-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
40 lines (33 loc) · 755 Bytes
/
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
const eqArrays = function(arr, arr1) {
let x = 0;
let u = arr.length;
for (let i = 0; i < arr.length; i++) {
if (arr[i] === arr1[i]) {
x++;
}
}
if (u < arr1.length) {
u = arr1.length;
}
if (x === u) {
return true;
} else {
return false;
}
};
const assertArrayEqual = function (actual, expected) {
if (eqArrays(actual, expected)) {
console.log("It's the same!")
} else {
console.log("It's difference!")
}
}
const map = function(array, callback) {
const results = [];
for (let item of array) {
results.push(callback(item));
}
return results;
}
const words = ["ground", "control", "to", "major", "tom"];
assertArrayEqual(map(words, word => word[0]), [ 'g', 'c', 't', 'm', 't' ]);