© 2026 LinearBytes Inc.
Search posts, tags, users, and pages
Zhe Wang
#2's reducer functions needs to return acc because acc.push returns the pushed item:
const squaresOfNumbers = numArray => numbers.reduce( (acc, item) => { acc.push(item * item); return acc; }, [] );
Sai Kishore Komanduri
Engineering an eGovernance Product | Hashnode Alumnus | I love pixel art
push returns the length of the array after the push operation; but, yea, we need to return acc. Thanks for pointing it out! Fixed it! :)
push
acc
David Chase
Lead Software Developer
Why not just use concat instead of push ? make its nice and compact and easy to follow along:
concat
const squaresOfNumbers = numArray => numArray.reduce((acc, item) => acc.concat(item * item), [])