v4
9/3/2021 by ygorbunkov -00
Setup HTML - click to add setup HTML
disable setup JavaScript
Setup JavaScript
const { random } = Math,

	randomStr = (minLen, maxLen) =>
		Array
			.from(
				{length: random()*(maxLen-minLen+1)+minLen},
				() => String.fromCharCode(random()*26+97)
			)
			.join(''),
			
	uniqueArray = Array
		.from(
			{length: 100},
			() => ({
				key: randomStr(3,7),
				value: randomStr(2,8)
			})
		),
		
	sourceArray = Array(1000)
		.fill()
		.map(() => uniqueArray[0|random()*uniqueArray.length])
			
delete caserun single casemove downdrag and drop case


ready



const dedupe = (arr, keyProp) => [
	...arr
		.reduce((acc, obj) => 
			(acc.set(obj[keyProp], obj), acc), new Map)
		.values()
]

dedupe(sourceArray, 'key')
delete caserun single casemove upmove downdrag and drop case


ready



  const dedupe = (arr, keyProp) => Array.from(new Set(arr.map((a) => a[keyProp]))).map(
    (Numbers) => {
      return arr.find((a) => a[keyProp] === Numbers);
    }
  )
  
  dedupe(sourceArray, 'key')
delete caserun single casemove upmove downdrag and drop case


ready



const dedupe = (arr, keyProp) => Object.values(Object.fromEntries(arr.map(a => [a[keyProp], a])));

dedupe(sourceArray, 'key')
delete caserun single casemove updrag and drop case


ready



const dedupe = ([...arr], keyProp) => {
	const numbers = new Set();

for (let i = arr.length - 1; i >= 0 ; i--) {
  const { [keyProp]: number } = arr[i];
  if (numbers.has(number)) arr.splice(i, 1);
  numbers.add(number);
}

return arr
}

dedupe(sourceArray, 'key')
Test Case - click to add another test case
Teardown JS - click to add teardown JavaScript
Output (DOM) - click to monitor output (DOM) while test is running
RUN