Skip to content

Instantly share code, notes, and snippets.

@EduardoRFS
Created May 9, 2021 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EduardoRFS/b31d079326aba4c4fe3bd134ee15b330 to your computer and use it in GitHub Desktop.
Save EduardoRFS/b31d079326aba4c4fe3bd134ee15b330 to your computer and use it in GitHub Desktop.
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