Skip to content

Commit

Permalink
feat: avoid data cloning in xSampling
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Nov 24, 2023
1 parent cf03423 commit 6c2a8bb
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/x/xSampling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ export function xSampling(
);
}

const clonedArray = array.slice();
returnArray.push(clonedArray[0]);
clonedArray.shift();
const delta = Math.floor(clonedArray.length / (length - 1));
returnArray.push(array[0]);
const delta = Math.floor((array.length - 1) / (length - 1));

for (
let i = delta - 1, j = 0;
i < clonedArray.length && j < length - 1;
let i = delta, j = 0;
i < array.length && j < length - 1;
i = i + delta, j++
) {
returnArray.push(clonedArray[i]);
returnArray.push(array[i]);
}

return returnArray;
Expand Down

0 comments on commit 6c2a8bb

Please sign in to comment.