Created
July 18, 2024 14:13
-
-
Save Connormiha/feed0d799a97152cac8030b119f7b85e to your computer and use it in GitHub Desktop.
spread vs unshift
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
// spread.js | |
let a = []; | |
console.time('1'); | |
for (let i = 0; i < 100; i++) { | |
const res = []; | |
for (let j = 0;j<5;j++) { | |
res.push(j); | |
} | |
a = [...res, ...a]; | |
} | |
console.timeEnd('1'); | |
console.log(a[100]); | |
//unshift.js | |
let a = []; | |
console.time('1'); | |
for (let i = 0; i < 100; i++) { | |
const res = []; | |
for (let j = 0;j<5;j++) { | |
res.push(j); | |
} | |
a.unshift(...res); | |
} | |
console.timeEnd('1'); | |
console.log(a[100]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment