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!
This kata is a subject to deduplication process here: https://github.com/codewars/content-issues/issues/181.
Please join the discussion to help us identify duplicate kata and retire them.
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
Thanks you. But I do not understand why 0 at the end is taken as the initial value or why and empty array causes an error you wont pass with "type checking" number == []
Loading more items...