What is the output?
Anonymous Quiz
44%
999 [ 2, 3, 99 ] 100 1
25%
999 [ 2, 3 ] 100 1
22%
999 [ 2, 3, 99 ] 4 1
9%
1 [ 2, 3, 99 ] 100 1
❤8👍2🔥2
CHALLENGE
function makeFns() {
const result = [];
for (var i = 0; i < 3; i++) {
let j = i;
result.push(() => i + j);
}
return result;
}
const fns = makeFns();
console.log(fns.map(f => f()).join(','));❤5🔥1
❤4👍1
CHALLENGE
class Base {}
class Derived extends Base {
static [Symbol.hasInstance](instance) {
return false;
}
}
const d = new Derived();
console.log(d instanceof Derived, d instanceof Base, Object.getPrototypeOf(Derived) === Base);👍3🔥2❤1
What is the output?
Anonymous Quiz
23%
false true false
42%
false true true
23%
true true true
13%
false false true
❤2
CHALLENGE
function* inner() {
yield 1;
yield 2;
return 'inner-done';
}
function* outer() {
const result = yield* inner();
yield result;
yield 3;
}
const gen = outer();
const results = [];
let r = gen.next();
while (!r.done) {
results.push(r.value);
r = gen.next();
}
console.log(results.join(','));
export {};❤5👍2🔥1
What is the output?
Anonymous Quiz
26%
1,2,inner-done,3,undefined
32%
1,2,undefined,3
33%
1,2,inner-done,3
9%
1,2,3
❤3👍2
CHALLENGE
const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);
const inc = x => x + 1;
const double = x => x * 2;
const square = x => x * x;
const f = compose(square, double, inc);
const g = pipe(square, double, inc);
console.log(f(2), g(2));
👍4🔥2❤1
❤1👍1🤩1
CHALLENGE
const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);
const add = n => x => x + n;
const mul = n => x => x * n;
const composed = compose(add(3), mul(2));
const piped = pipe(add(3), mul(2));
console.log(composed(5), piped(5));
🔥4❤1
🔥2❤1👍1
CHALLENGE
const proto = { inherited: 'nope' };
const obj = Object.create(proto);
obj.b = 2;
obj[1] = 'one';
obj.a = 1;
Object.defineProperty(obj, 'hidden', { value: 'secret', enumerable: false });
obj[Symbol('sym')] = 'symbolValue';
console.log(
Object.keys(obj).join(','),
Object.values(obj).join(','),
Object.entries(obj).length
);👍2❤1🔥1
What is the output?
Anonymous Quiz
25%
1,b,a one,2,1 4
31%
a,b,1 1,2,one 3
28%
b,a,1 2,1,one 3
16%
1,b,a one,2,1 3
❤1👍1🔥1
CHALLENGE
function partial(fn, ...presetArgs) {
return (...laterArgs) => fn(...presetArgs, ...laterArgs);
}
const add = (a, b, c) => a + b + c;
const addFive = partial(add, 5);
const addFiveTen = partial(addFive, 10);
console.log(addFiveTen(1), addFive(2, 3));
export {};❤3🔥3👍1
🔥3👍1
CHALLENGE
const nums = [40, 100, 1, 5, 25, 10];
nums.sort();
console.log(nums.join(' '));
❤3🤣3
What is the output?
Anonymous Quiz
51%
1 5 10 25 40 100
25%
1 10 100 25 40 5
14%
100 40 25 10 5 1
11%
1 10 25 40 100 5
❤2
CHALLENGE
class Range {
#start; #end;
constructor(start, end) { this.#start = start; this.#end = end; }
[Symbol.iterator]() {
let current = this.#start;
const end = this.#end;
return {
next() {
return current < end
? { value: current++, done: false }
: { value: undefined, done: true };
},
[Symbol.iterator]() { return this; }
};
}
}
const range = new Range(1, 5);
const arr1 = [...range];
const arr2 = [...range];
const sum = arr1.reduce((a, b) => a + b, 0);
console.log(arr1.join(','), arr2.join(','), sum);❤1👍1
What is the output?
Anonymous Quiz
18%
1,2,3,4 10
35%
1,2,3,4 1,2,3,4 0
33%
1,2,3,4 1,2,3,4 10
14%
1,2,3,4,5 1,2,3,4,5 15
❤3
CHALLENGE
const log = [];
async function a() {
log.push('a-start');
await b();
log.push('a-end');
}
async function b() {
log.push('b-start');
await Promise.resolve();
log.push('b-end');
}
a();
log.push('sync-end');
setTimeout(() => console.log(log.join(',')), 0);
❤1🔥1