Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions src/filters/arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,18 @@ function matchItems(array1, array2, index1, index2, context) {
// no way to match objects was provided, try match by position
return context.matchByPosition && index1 === index2;
}
let hash1;
let hash2;
if (typeof index1 === 'number') {
context.hashCache1 = context.hashCache1 || [];
hash1 = context.hashCache1[index1];
if (typeof hash1 === 'undefined') {
context.hashCache1[index1] = hash1 = objectHash(value1, index1);
}
} else {
hash1 = objectHash(value1);
context.hashCache1 = context.hashCache1 || [];
let hash1 = context.hashCache1[index1];
if (typeof hash1 === 'undefined') {
context.hashCache1[index1] = hash1 = objectHash(value1, index1);
Comment on lines -53 to +56
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index1 will always be a number based on the usages of this method (i.e., matchItems). matchItems is not exported so there is no concern of it being used differently by users.

}
if (typeof hash1 === 'undefined') {
return false;
}
if (typeof index2 === 'number') {
context.hashCache2 = context.hashCache2 || [];
hash2 = context.hashCache2[index2];
if (typeof hash2 === 'undefined') {
context.hashCache2[index2] = hash2 = objectHash(value2, index2);
}
} else {
hash2 = objectHash(value2);
context.hashCache2 = context.hashCache2 || [];
let hash2 = context.hashCache2[index2];
if (typeof hash2 === 'undefined') {
context.hashCache2[index2] = hash2 = objectHash(value2, index2);
Comment on lines -67 to +64
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index2 will always be a number based on the usages of this method (i.e., matchItems). matchItems is not exported so there is no concern of it being used differently by users.

}
if (typeof hash2 === 'undefined') {
return false;
Expand Down
6 changes: 1 addition & 5 deletions src/filters/lcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ const get = function (array1, array2, match, context) {
match || defaultMatch,
innerContext,
);
const result = backtrack(matrix, array1, array2, innerContext);
if (typeof array1 === 'string' && typeof array2 === 'string') {
result.sequence = result.sequence.join('');
}
return result;
return backtrack(matrix, array1, array2, innerContext);
Copy link
Collaborator Author

@Methuselah96 Methuselah96 Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array1 and array2 are never strings based on the usages of lcs.get. lcs.get is not exported through the package entrypoint so there is no concern of it being used differently by users.

};

export default {
Expand Down
6 changes: 1 addition & 5 deletions src/formatters/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,7 @@ class BaseFormatter {
if (arrayKeys && key === '_t') {
continue;
}
const leftKey = arrayKeys
? typeof key === 'number'
? key
: parseInt(trimUnderscore(key), 10)
: key;
const leftKey = arrayKeys ? parseInt(trimUnderscore(key), 10) : key;
Copy link
Collaborator Author

@Methuselah96 Methuselah96 Sep 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key cannot be a number because all of the values pushed to the keys array are strings. keys and key are both local variables so there is no concern of it being used differently by users.

const isLast = index === length - 1;
fn(key, leftKey, moveDestinations[leftKey], isLast);
}
Expand Down