Is this correct?

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

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”.

1 Like