Skip to content

Latest commit

 

History

History
20 lines (17 loc) · 534 Bytes

square_n_sum.md

File metadata and controls

20 lines (17 loc) · 534 Bytes

Description

Complete the square sum function so that it squares each number passed into it and then sums the results together.

For example, for [1, 2, 2] it should return 9 because 12+22+22=9.

My Solution

def square_sum(numbers)
  numbers.sum{ |num| num**2 }
end

Better/Alternative solution from Codewars

def squareSum(numbers)
  numbers.map {|n| n*n}.reduce(:+)
end