Bugs
One line version with error output as lambda (analog of arrow function in Python) looks like this.
div = lambda num1, num2 : print("Division failed: division by zero") if num2 == 0 else print("Division failed: integers and floats accepted only") if not(isinstance(num1, (int, float)) and isinstance(num2, (int, float))) else num1 / num2
let divide = (num1, num2) => num2 === 0 ? console.log("Division failed: division by zero") : !(num1 === +num1 && num2 === +num2) ? console.log("Division failed: integers and floats accepted only") : num1/num2- div = lambda num1, num2 : print("Division failed: division by zero") if num2 == 0 else print("Division failed: integers and floats accepted only") if not(isinstance(num1, (int, float)) and isinstance(num2, (int, float))) else num1 / num2
Fundamentals
Arrays
Data Types
Different way wihout using reduce
and forEach
.