const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squaredIntegers = arr.reduce((acc,realNumberArray)=>acc+realNumberArray,0);
Why do you have ,0
after ârealNumberArrayâ?
What is it that you want to happen? Can you explain your logic in writing the code?
acc is starting with zero. I read this somewhere.
I am just trying to sum the entire array
I need clarity over this
You are almost there, try reading the documentation on the method I linked and see if you can figure it out
It is important to know how to do that
If you canât I will help further
For the starting value, you donât need to express it, you can just use the callback as argument of the reduce method
arr.reduce(callback)
you specify a starting value if it is different than 0, but if it is 0 it is not needed - it works anyway
arr.reduce(callback, startingValue)
(It had just confused me the fact that you didnât have brackets around the body of the callback, just a trick of my brain)
It is not wrong what you did there - the error is somewhere else and much more important
My bad I guess I have written
It should be ârealNumberArrayâ instead of âarrâ.