Sum of squares
func sum_of_squares(vector) {
var sum = 0
vector.each { |n| sum += n**2 }
return sum
}
say sum_of_squares([]) # 0
say sum_of_squares([1,2,3]) # 14
PreviousSum of square and cube digits of an integer are primesNextSum of the digits of n is substring of n
Last updated
Was this helpful?