October 02, 2017

Uniquify a two dimensional array

Use the following function to get non-duplicate version of a two-dimensional​ array

const unique = (arr) => {
	let map = {};
	return arr.filter((item) => {
		if (item in map) return false;
		else {
			map[item] = true;
			return true;
		}
	});
};

uique([
	[1, 2],
	[1, 2],
]);
//=> [[1,2]]