multiply function javascript
// MULTIPLY FUNCTION
const multiply = (num1, num2) => {
return num1 * num2;
};
let resulMultiply = multiply(4, 5);
console.log(resulMultiply);
// 20
multiply function javascript
// MULTIPLY FUNCTION
const multiply = (num1, num2) => {
return num1 * num2;
};
let resulMultiply = multiply(4, 5);
console.log(resulMultiply);
// 20
multiply all numbers in an array javascript
The cause is already known. Here's an alternative - using Array.reduce for your method:
console.log( [1, 2, 3].reduce( (a, b) => a * b ) );
console.log( Array.from( {length: 20} )
.map( (v, i) => i + 1 )
.reduce( (a,b) => a * b )
.toLocaleString());
// for empty arrays, use some initial value
const arr = [];
if (arr.reduce( (a, b) => a * b, -1 ) === -1) {
console.error(`The given array ${arr} is empty`);
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us