Javascript:
function array_product ( input ) { // Calculate the product of values in an array
//
// + original by: _argos
var Index = 0, Product = 1;
if ( input instanceof Array ) {
while ( Index < input.length ) {
Product *= ( !isNaN ( input [ Index ] ) ? input [ Index ] : 0 );
Index++;
}
} else {
Product = null;
}
return Product;
}
Примеры:
array_product([ 2, 4, 6, 8 ]);
384
|
|
|
|