programming-examples/js/Array/Write a JavaScript program to find the sum of squares of a numeric vector..js

9 lines
190 B
JavaScript
Raw Normal View History

2019-11-15 12:59:38 +01:00
function sum_sq(array) {
var sum = 0,
i = array.length;
while (i--)
sum += Math.pow(array[i], 2);
return sum;
}
console.log(sum_sq([0,1,2,3,4]));