22 lines
527 B
JavaScript
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]));
|