For the following JavaScript code how would one work out the evaluation/execution order? Excluding Operator precedence, and focusing on the function squareList can one apply the principles of "Right to left" and "inside out" to the code?
What I mean by that is the first statement evaluated by JS in this case would be:
return num > 0 && num % parseInt(num) === 0;
One this has been evaluated for each item in the array, we will then progress to the line
return arr.filter(function (num) {
And finally:
return Math.pow(num, 2);
If I am thinking about this in the wrong way then I need some help please, how can I use a guide or official resouce to know the evaluation/execution order and what will be run first? and the statements following on from that in what order?
entire code block:
const squareList = function squareList(arr) {
return arr.filter(function (num) {
return num > 0 && num % parseInt(num) === 0;
}).map(function (num) {
return Math.pow(num, 2);
});
};
const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
console.log(squaredIntegers);
filter(evaluating the conditional statement) for each item in the array, returning a new array, then themap(evaluating theMath.pow) for each item in the array, returning a new array