MCPcopy Index your code
hub / github.com/javascriptdata/danfojs / getDuplicate

Method getDuplicate

src/danfojs-base/shared/utils.ts:709–734  ·  view source on GitHub ↗

* Get duplicate values in a array * @param arr

(arr: Array<T>)

Source from the content-addressed store, hash-verified

707 * @param arr
708 */
709 getDuplicate<T>(arr: Array<T>) {
710 const tempObj: any = {};
711 const resultObj: any = {};
712
713 for (let i = 0; i < arr.length; i++) {
714 const val = arr[i];
715 if (this.keyInObject(tempObj, val as unknown as string | number)) {
716 tempObj[val]["count"] += 1;
717 tempObj[val]["index"].push(i);
718 } else {
719 tempObj[val] = {};
720 tempObj[val]["count"] = 1;
721 tempObj[val]["index"] = [i];
722 }
723 }
724
725 for (let key in tempObj) {
726 if (tempObj[key]["count"] >= 2) {
727 resultObj[key] = {};
728 resultObj[key]["count"] = tempObj[key]["count"];
729 resultObj[key]["index"] = tempObj[key]["index"];
730 }
731 }
732
733 return resultObj;
734 }
735
736 /**
737 * Returns the index of a sorted array

Callers 2

utils.test.jsFile · 0.80
utils.test.tsFile · 0.80

Calls 1

keyInObjectMethod · 0.95

Tested by

no test coverage detected