r/learnjavascript • u/OsamuMidoriya • Jul 11 '24
debugging problem
My teacher was telling us about debugging, and how it's basically figuring out why a code is not working and that's what we will be spending most of our time on the job doing. He gave us the example below. we come into work and a coworker gives us this code because its not working(it works),together we was worked on it step by step what it does. NOTE this is not original we renamed something to make it easier to read.
I understand what this code does, the problem I am having is the [] at the end of the function.
const flattend = [[0, 1], [2, 3], [4, 5]].reduce{
(accumulator, array) => accumulator.concat(array), []);he said that the code is saying the accumulator should start off as an empathy array [] and it basically saying
(accumulator, array) => [].concat(array), []);I'm not sure why or how the [] is the accumulator, because of this I'm now unsure how to tell what the perimeter will be in any code
View all comments
Show parent comment
1
u/OsamuMidoriya Jul 12 '24
Thank you as I put in my original post I understand what it does and what the output will be, and I know what concat does to array my problem was with reduce and the placement of the [] . You can look at my reply to sepp2k for more information and the video I learned reduce from