Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 1x 1x 5x 5x 5x 2x 6x 2x 2x 6x 3x 6x 2x 2x 6x 5x | const STEP = 10; // const MAX_VALUE = 2147483647; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // ts-ignore export const reOrder = <T extends Record<string, any>>(data: T[], sortByKey: string, desc?: boolean): [T[], T[]] => { let previousOrder = 0; const changedElements: T[] = []; if (desc) { for (let i = data.length - 1; i >= 0; --i) { if (previousOrder >= data[i][sortByKey]) { (data[i][sortByKey] as number) = previousOrder + STEP; changedElements.push(data[i]); } previousOrder = data[i][sortByKey]; } } else { for (let i = 0; i < data.length; ++i) { if (previousOrder >= data[i][sortByKey]) { (data[i][sortByKey] as number) = previousOrder + STEP; changedElements.push(data[i]); } previousOrder = data[i][sortByKey]; } } return [data, changedElements]; }; |