JSFiddle - React, Tailwind, and code Playground

by brigand

JavaScript

function uniqBy(items, getKey) {
	const found = new Set();
  
  return items.filter((item) => {
	  const key = getKey(item);
    if (found.has(key)) {
	    return false;
    }
    found.add(key);
    return true;
  });
}

const res = uniqBy([1, 2, 3, 4, 5, 6, 7, 8], (x) => Math.floor(x / 3));
console.log(res);