-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
39 lines (32 loc) · 946 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
//The map function will return a new array based on the results of the callback function.
const words = ["ground", "control", "to", "major", "tom"];
const map = (arr, callback) => {
const results = [];
for (let i of arr) {
results.push(callback(i));
}
return results;
};
module.exports = map;
const results1 = map(words, word => word[0]);
console.log(results1);
//assertArraysEqual function
const assertArraysEqual = function(Array1, Array2) {
if (eqArrays(Array1, Array2)) {
console.log(`Assertion Passed: ${Array1} ✅✅✅ ${Array2}`);
} else {
console.log(`Assertion Failed: ${Array1} 🛑🛑🛑 ${Array2}`);
}
};
//eqArrays function
const eqArrays = function(Array1, Array2) {
if (Array.isArray(Array1) &&
Array.isArray(Array2)) {
for (const [i, value] of Array1.entries()) {
const value2 = Array2[i];
if (value !== value2) {
return false;
}
}
} return true;
};