Skip to content

Instantly share code, notes, and snippets.

Last active November 9, 2022 11:21
What would you like to do?
// Replace items in `as` with a matching `id` with the
// respective item in `bs`, otherwise append new items.
const abs = Object.fromEntries([ => [, a]), => [, b])
// The 'trick' is that if you have two entries with the same id
// (in this case, implying that the value was updated within `bs`)
// then with this method the value of the right-most entry will be used.
Copy link

sebinsua commented Nov 9, 2022

If I get time I will implement an immutable version of Counter.

function total(map) {
  return map.values().reduce((acc, count) => acc + count, 0);

function mostCommon(map, n) {
  // ...
  // Not trivial to do well, so I'll come back to this... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment