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(','));
❤1👍1🔥1
Please open Telegram to view this post
VIEW IN TELEGRAM
❤6👍3🔥1
CHALLENGE
const obj = { a: 1, b: { c: 2 } };
const frozen = Object.freeze(obj);
frozen.a = 99;
frozen.b.c = 88;
frozen.d = 77;
const sealed = Object.seal({ x: 10, y: 20 });
sealed.x = 30;
sealed.z = 40;
delete sealed.y;
console.log(obj.a, obj.b.c, obj.d);
console.log(sealed.x, sealed.y, sealed.z);
What is the output?
Anonymous Quiz
25%
99 88 77, 30 20 40
48%
1 88 undefined, 30 20 undefined
20%
1 2 undefined, 10 20 undefined
7%
99 2 77, 30 undefined 40
❤4👍1🔥1