TGViewer
Channel Public Channel
JavaScript

JavaScript

@javascript

A resourceful newsletter featuring the latest and most important news, articles, books and updates in the world of #javascript 🚀 Don't miss our Quizzes!

Let's chat: @nairihar
Subscribers
31.1K
Photos
1.2K
Videos
10
Links
894

Showing posts older than #3468 · Back to latest

Older Posts 20 shown
Post #3467 2.24K
  • ❤ 1
  • 👍 1
  • 🔥 1
Post #3466 2.18K
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
Post #3465 2.24K
  • 🔥 2
  • ❤ 1
  • 👍 1
Post #3464 2.17K
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
Post #3463 2.4K
🔥
  • 🔥 24
  • 🤣 9
  • ❤ 6
  • 🤩 2
  • 👍 1
  • 🤔 1
Post #3462 2.15K
  • ❤ 1
  • 👍 1
  • 🤩 1
Post #3461 2.12K
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
Post #3460 2.26K
  • ❤ 3
  • 👍 2
Post #3459 2.19K
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
Post #3457 2.13K
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
Post #3456 2.34K
  • ❤ 4
  • 👍 1
Post #3455 2.12K
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
Post #3454 2.36K
  • ❤ 8
  • 👍 2
  • 🔥 2
Post #3453 2.28K
CHALLENGE

const arr = [1, [2, 3], { a: 4 }];
const copy = [...arr];
copy[1].push(99);
copy[2].a = 100;
arr[0] = 999;

console.log(arr[0], arr[1], arr[2].a, copy[0]);
  • 👍 2
  • 🔥 1
Post #3451 2.28K
CHALLENGE

const a = Math.max();
const b = Math.min();
const c = 0.1 + 0.2 === 0.3;
const d = Math.max(1, NaN, 3);
const e = [1, 2, 3].reduce((sum, n) => sum + n, 0) / 3;
const f = Number.isInteger(5.0);
console.log(a, b, c, d, e, f);
  • 👍 2
Post #3449 2.11K
CHALLENGE

function makeCounters() {
const counters = [];
for (var i = 0; i < 3; i++) {
let j = i;
counters.push(() => `${i}-${j}`);
}
return counters;
}
const [a, b, c] = makeCounters();
console.log(a(), b(), c());
export {};
  • ❤ 4
  • 👍 1
  • 🔥 1
Older posts →
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 →