* Add a limit to the number of error messages sent from validations to be rendered in the debugger
18 lines
603 B
TypeScript
18 lines
603 B
TypeScript
// Finds the first index which is a duplicate value
|
|
// Returns -1 if there are no duplicates
|
|
// Returns the index of the first duplicate entry it finds
|
|
|
|
// Note: This "can" fail if the object entries don't have their properties in the
|
|
// same order.
|
|
export const findDuplicateIndex = (arr: Array<unknown>) => {
|
|
const _uniqSet = new Set();
|
|
let currSetSize = 0;
|
|
for (let i = 0; i < arr.length; i++) {
|
|
// JSON.stringify because value can be objects
|
|
_uniqSet.add(JSON.stringify(arr[i]));
|
|
if (_uniqSet.size > currSetSize) currSetSize = _uniqSet.size;
|
|
else return i;
|
|
}
|
|
return -1;
|
|
};
|