Implement a function squareSum
so that it squares any number(s) passed into it and then adds the squares together.
For example, for [1, 2, 2]: it should return 9 because 1^2 + 2^2 + 2^2 = 9.
Tests
[1, 2, 3, 4]
[0, 3, 5, 7]
[2, 2, 20]
Good luck!
This challenge comes from jhoffner on CodeWars. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge idea for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (13)
Javascript:
Trying to find a more... unconventional javascript answer :D
you can actually get rid of the
map
I am in love with Python.
Btw, you gave "tests" but the tests don't have the supposed results. I know I can hand calculate but still they are not complete test cases.
Point free baby!
(Obviously this is probably too polymorphic, you could just limit it to
[Int] -> Int
)Sum of squares is the default example of the Rayon crate:
(this runs in parallel)
Apparently people here are really into onelinerization.
No parallelism, but at least it's shorter than Python.
Elm
I really wish flip is part of the core library...
My swift solution :
Python
Elixir
JS:
Kotlin