TGViewer
JavaScript JavaScript @javascript · 31.1K subscribers
Post #2594 4.14K
CHALLENGE

const arr = new Array(1000000).fill(0).map((_, i) => i);
const results = [];

function method1() {
return arr.filter(x => x % 2 === 0).map(x => x * 2).slice(0, 3);
}

function method2() {
const result = [];
for (let i = 0; i < arr.length && result.length < 3; i++) {
if (arr[i] % 2 === 0) {
result.push(arr[i] * 2);
}
}
return result;
}

console.log(method1().join(','));
console.log(method2().join(','));
More from @javascript
  1. Oct 2, 2026Post #3532
  2. Oct 2, 2026CHALLENGE const arr = [1, 2, 3]; const log = []; const result = arr.map((x, i) => { if (i…
  3. Oct 1, 2026Post #3530
  4. Oct 1, 2026CHALLENGE class Counter { #count = 0; static #instances = 0; constructor() { Counter.#inst…
  5. Sep 30, 2026Post #3528
  6. Sep 30, 2026CHALLENGE const message = 'a😀bc'; const codePoints = [...message]; const combined = { raw…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →