Hello can you tell me what is the difference with this two?
this works fine
const filteredIntegers = arr.filter((arr) => arr % 1 == 0);
const squaredIntegers = filteredIntegers.map((arr) => Math.pow(arr,2));
this does nothing
const squaredIntegers = arr.map((arr) => Math.pow(arr.filter((arr) => arr % 1 == 0),2));
is there any way to simplify the first one? thank you.
You’re trying to square an array in the second one (Math.pow(filteredArray, 2)
) which doesn’t make sense
arr.filter((n) => n % 1 == 0).map((n) => Math.pow(n,2));
And be careful what you call parameters: this
arr.filter((arr) => arr % 1 == 0);
Is really confusing. You have an array you’re calling arr
that you are filtering. Then you’re calling every value in that array arr
as well
I get it now hahaha
Thank you, sir.
1 Like