DEV Community

Discussion on: Daily Challenge #225 - Square'n'Sum

Collapse
 
kesprit profile image
kesprit

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