Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Why do you have a zero at the end of the callback function?
With all due respect, you are not right. Function squareSum() takes one argument, not two. Let me explain: func squareSum([],[1,2,2]) will only look for a first argument, which is [] (empty array), and thus result is 0. Also, if you would to call func squareSum([1,2,2], []), the result would be, as expected, 9.
Me too! x
add 0 or [] to reduce, (sum, 0) for example. this Excercise is fundamentally wrong because it returns purposefully zero when given and empty array so, don't be upset about this challenge.
None of these functions solve the problem; for example
squareSum([],[1,2,2]) returns zero, which is WRONG!
it should return 9 and not 0!!!!
like i did ?
i think mine looks clear and one liner,
You've been warned 4 times about using spoiler flag when commenting a solution like this, there won't be more warnings. Your posts are visible in the homepage to people who didn't solve the kata yet, that's the reason you should use it.
Had to lookup what was going on here.. Here's what I found!
This function, squareSum, takes an array of numbers as input and returns the sum of the squares of each number in the array. Here's how it works:
The reduce method takes two arguments: a callback function and an initial value. The callback function takes two arguments: an accumulator (in this case, the running sum) and the current element in the array being processed.
In this function, the callback function squares the current element (n) using the * operator and adds it to the running sum (sum). The result of this operation becomes the new value of sum, and the process repeats for each element in the array.
Finally, when all elements in the array have been processed, the final value of sum is returned by the reduce method as the result of the function.
Gret job!
nice
I wish I had thought this solution!
Set the initial value of your reduce to 0
i dont think using different orders in parameters and arguments is a good idea. Can be very confusing for readers
This comment is hidden because it contains spoiler information about the solution
Here we go: jsbench.me/ffl0wgbw9g/1 sorry for late response, it shouldn't really matter but just FYI. I was probably pretty sleep deprived when commented this, don't think of me like i'am trying to be smartass or something
Loading more items...