TGViewer
JavaScript JavaScript @javascript · 31K subscribers
Post #1617 5.89K
Sponsored by Bryntum 👮‍♀️
World Class Web Components

❓ CHALLENGE


const weakMap = new WeakMap();
const arr = [1, 2, 3, 4];
const objs = arr.map(n => ({ n }));

objs.forEach((obj, index) => weakMap.set(obj, arr.slice(0, index + 1)));

const result = objs.map(obj => weakMap.get(obj).reduce((acc, num) => acc + num, 0));

console.log(result);
  • 👍 7
  • ❤ 2
  • 🤔 2
More from @javascript
  1. Oct 16, 2026Post #3564
  2. Oct 16, 2026CHALLENGE const x = 0; const y = ''; const z = null; const r1 = x ?? y ? 'A' : 'B'; const…
  3. Oct 15, 2026🤟 You Don’t Know Node.js EventLoop (30 min read) You might be wondering if the title of t…
  4. Oct 15, 2026Post #3561
  5. Oct 15, 2026CHALLENGE class EventBus { #listeners = new Map(); on(event, cb) { if (!this.#listeners.ha…
  6. Oct 14, 2026💻 Deno is Joining Cloudflare (But…) Maybe David Bushell saw the writing on the wall, as t…
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 →