PromucFlow_constructor/app/client/src/workers/helpers.ts
Abhinav Jha aee5816a54
fix: limit validation errors in debugger (#10886)
* Add a limit to the number of error messages sent from validations to be rendered in the debugger
2022-02-08 17:13:25 +05:30

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;
};