-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.js
44 lines (32 loc) · 1.01 KB
/
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
const assertArraysEquals = function(bool) {
if (bool === true) {
console.log("Assertation Passed: These arrays are the same!");
} else {
console.log("Assertation Failed: These arrays are different!");
}
};
const eqArrays = function(num1, num2) {
let newNum1 = num1;
let newNum2 = num2;
if (num1.toString() === num2.toString()) {
assertArraysEquals(true);
} else {
console.log(newNum1 + " !== " + newNum2);
assertArraysEquals(false);
}
};
//map function will take in two arguments and return a new array based on results of callbackFunction
//argument1: arrayTOMap
//argument2: callbackFunction
const words = ["ground", "control", "to", "major", "tom"];
const moreWords = ["round", "ontrol", "o", 'ajor', 'om'];
const map = function (array, callback) {
const results = [];
for (let item of array) {
results.push(callback(item));
}
return results;
};
const results1 = map(words, word => word[0]);
const results2 = map(moreWords, word => word[0]);
eqArrays(results1,results2);