loading...

re: Daily Challenge #225 - Square'n'Sum VIEW POST

FULL DISCUSSION
 

My swift solution :

func squareSum(_ array: [Int]) -> Int {
    Int(array.reduce(into: 0.0) { $0 += pow(Double($1), 2) })
}

squareSum([1, 2, 2]) // 9
squareSum([1, 2, 3, 4]) // 30
squareSum([0, 3, 5, 7]) // 83
squareSum([2, 2, 20]) // 408
squareSum([]) // 0
code of conduct - report abuse