diff options
| author | Bobby <[email protected]> | 2022-01-28 17:22:24 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-01-28 17:22:24 -0500 |
| commit | d70d0b343d70f7d8b5a87abdf8200de274ea8de0 (patch) | |
| tree | 9685f15c08f749b9aa14123030562a8169c041b2 /src/lib | |
| parent | 6645a8a8ddcbc46b20f1c662ee259da3315e8d51 (diff) | |
| download | izuku.js-d70d0b343d70f7d8b5a87abdf8200de274ea8de0.tar.xz izuku.js-d70d0b343d70f7d8b5a87abdf8200de274ea8de0.zip | |
feat: removeDuplicates function
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/data.ts | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lib/data.ts b/src/lib/data.ts index 480c309..c6ee585 100644 --- a/src/lib/data.ts +++ b/src/lib/data.ts @@ -230,3 +230,29 @@ export function sort( this.rowdata = sorted; return this; } + +/** + * removeDuplicates - removes the duplicate rows from a column + * @param column: the column index or column name + * @returns the rowdata without duplicates + */ +export function removeDuplicates(this: Frame, column: string | number): Frame { + const columnIndex = + typeof column === 'number' ? column : this.columns.indexOf(column); + if (columnIndex === -1) { + throw new Error('Invalid column index'); + } + const rowdata = this.rowdata; + + // remove the duplicates from rowdata based on column index + const unique = rowdata.filter((row: any[], index: number) => { + for (let i = 0; i < index; i++) { + if (row[columnIndex] === rowdata[i][columnIndex]) { + return false; + } + } + return true; + }); + this.rowdata = unique; + return this; +} |
