-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
32 lines (27 loc) · 844 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
const map = function (arr, callback){
const results = [];
for (let item of arr) {
results.push(callback(item));
}
return results;
};
const eqArrays = function(array1, array2) {
if (array1.length !== array2.length) {
return false;
}
for (let i = 0; i < array1.length; i ++) {
if (array1[i] !== array2[i]) {
return false;
}
}
return true;
};
const assertArraysEqual = function(arr1, arr2) {
if (eqArrays(arr1, arr2)) { //if the true (two arrays are equal)
console.log(`😜😍🍆Arrays are equal! ${arr1} === ${arr2}`);
} else {
console.log(`😡🤮🤢Arrays are NOT equal! ${arr1} !== ${arr2}`);
}
};
const words = ["ground", "control", "to", "major", "tom"];
assertArraysEqual(map(words, word => word.length), [6, 7, 2, 5, 3]);