Skip to content

Commit

Permalink
revised l2pool2d
Browse files Browse the repository at this point in the history
  • Loading branch information
mei1127 committed Jan 12, 2024
1 parent de57d69 commit 46ce01c
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/reduce.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,12 @@ export function reduceL1(input, options = {}) {

/* The l2 reducer */
export function l2Reducer(previousValue, currentValue, currentIndex, array) {
if (currentIndex== 1) {
const sumOfSquares = previousValue*previousValue + currentValue * currentValue;
if (currentIndex == 1) {
const sumOfSquares = previousValue * previousValue + currentValue * currentValue;
return sumOfSquares;
} else if (currentIndex === array.length - 1) {
const sumOfSquares = previousValue + currentValue * currentValue;
return Math.sqrt(sumOfSquares);
} else {
const sumOfSquares = previousValue + currentValue * currentValue;
return sumOfSquares;
return (currentIndex === array.length - 1) ? Math.sqrt(sumOfSquares) :sumOfSquares;
}
}

Expand Down

0 comments on commit 46ce01c

Please sign in to comment.