This language bar is your friend. Select your favorite languages!

Idiom #202 Sum of squares

Calculate the sum of squares s of data, an array of floating point values.

import java.util.Arrays;
Arrays.stream(data).map(i -> i * i).sum()
s = sum( data**2 )
s = data.reduce((a, c) => a + c ** 2, 0)
math
var
  data: array of double;
...
  s := SumOfSquares(data);
...
use List::Util qw(sum);
my $s = sum map { $_ ** 2 } @data;
s = sum(i**2 for i in data)
s = data.sum{|i| i**2}

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

Bart