When utilizing flowtype
, our preference is to use const
over let
I have a function that needs to be executed with optimal performance, and it effectively compares two arrays with ids. This serves as a great example for my question:
/**
* @function compare
* @description function compares two arrays with ids to figure out: are they equal? (elements position can be different)
* @param arraFrom {Array}
* @param arraTo {Array}
* @param compareFunction {Function}
* @returns {Boolean}
*/
function compare(arraFrom, arraTo, compareFunction) {
let notEqual = true;
if(arraFrom.length !== arraTo.length) return false;
for (let i = 0; i < arraFrom.length; i++) {
notEqual = true;
for (let j = 0; j < arraTo.length; j++) {
if (compareFunction ?
compareFunction(arraFrom[i], arraTo[j]) :
arraFrom[i] === arraTo[j]) {
notEqual = false;
break;
}
}
if (notEqual) return false;
}
return true;
}
My question is: in what way can we implement the function without the use of let
for optimal performance?
Thanks in advance!