You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
programming-examples/js/Math/Subtract elements from one ...

22 lines
527 B
JavaScript

function subtraction(arr)
{
if (Object.prototype.toString.call(arr) === '[object Array]') {
var total = arr[0];
if (typeof (total) !== 'number') {
return false;
}
for (var i = 1, length = arr.length; i < length; i++)
{
if (typeof (arr[i]) === 'number')
{
total -= arr[i];
}
else
return false;
}
return total;
}
else
return false;
}
console.log(subtraction([7,3, 2,-1]));