Skip to content

Commit

Permalink
Merge pull request #3 from alexreardon/using-for-loop
Browse files Browse the repository at this point in the history
Using for loop
  • Loading branch information
alexreardon authored Apr 8, 2019
2 parents c8acc64 + 16618b4 commit 06e96c2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/are-inputs-equal.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
// @flow
const isShallowEqual = (newValue: mixed, oldValue: mixed): boolean =>
newValue === oldValue;

export default function areInputsEqual(
newInputs: mixed[],
lastInputs: mixed[],
) {
return (
newInputs.length === lastInputs.length &&
newInputs.every(
(newArg: mixed, index: number): boolean =>
isShallowEqual(newArg, lastInputs[index]),
)
);
// no checks needed if the inputs length has changed
if (newInputs.length !== lastInputs.length) {
return false;
}
// Using for loop for speed. It generally performs better than array.every
// https://github.com/alexreardon/memoize-one/pull/59

for (let i = 0; i < newInputs.length; i++) {
// using shallow equality check
if (newInputs[i] !== lastInputs[i]) {
return false;
}
}
return true;
}

0 comments on commit 06e96c2

Please sign in to comment.