// 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) => { 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; };