Javascript filter unique / duplicates closure

Date: 2020-08-20
const filterUnique = () => {
	const keys = new Set();
	return (key) => !keys.has(key) ? keys.add(key) || true : false;
};

const filterById = filterUnique();
console.log([{ id: 1 },{ id: 2 },{ id: 3 },{ id: 2 }].filter(x => filterById(x.id)));

39180cookie-checkJavascript filter unique / duplicates closure