Created
May 9, 2021 16:19
-
-
Save EduardoRFS/b31d079326aba4c4fe3bd134ee15b330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const tests = [ | |
[ | |
"for", | |
(array) => { | |
const new_array = new Array(3); | |
for (let index = 0; index < array.length; index++) { | |
new_array[index] = array[index] + 1; | |
} | |
return new_array; | |
}, | |
], | |
[ | |
"map", | |
(array) => { | |
return array.map((el) => el + 1); | |
}, | |
], | |
["map call", (array) => { | |
return Array.prototype.map.call(array, (el) => el + 1); | |
}], | |
]; | |
const inputs = [ | |
[1, 2, 3], | |
(() => { | |
const arr = [1]; | |
arr[2] = 3; | |
return arr; | |
})(), | |
{ length: 3 }, | |
{ map: () => console.log("tuturu") }, | |
]; | |
tests.forEach(([name, test]) => { | |
inputs.forEach((input) => { | |
try { | |
console.log(name, test(input)) | |
} catch (e) { | |
console.log(name, 'fail') | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment