Ad

Refactor the function to an arrow function returning the value in one line.

Code
Diff
  • isEven = num => num % 2 === 0 ? true : num % 1 === 0 ? false : undefined;
    
    // Previous iteration
    
    // function isEven(num) {
    //   return num % 2 === 0 ? true : num % 1 === 0 ? false : undefined;
    // }
    
    • function isEven(num) {
    • return num % 2 === 0 ? true : num % 1 === 0 ? false : undefined;
    • }
    • // isEven(2);
    • isEven = num => num % 2 === 0 ? true : num % 1 === 0 ? false : undefined;
    • // Previous iteration
    • // isEven = number => number %2 === 0 ?
    • // true: number %1 === 0 ?
    • // false : undefined;
    • // function isEven(num) {
    • // return num % 2 === 0 ? true : num % 1 === 0 ? false : undefined;
    • // }

Refactor the previous function body to one line.

Code
Diff
  • function isEven(num) {
      return num % 2 === 0 ? true : num % 1 === 0 ? false : undefined;
    }
    // isEven(2);
    
    
    // Previous iteration
    
    // isEven = number => number %2 === 0 ? 
    //   true: number %1 === 0 ? 
    //   false : undefined;
    • isEven = number => number %2 === 0 ?
    • true: number %1 === 0 ?
    • false : undefined;
    • function isEven(num) {
    • return num % 2 === 0 ? true : num % 1 === 0 ? false : undefined;
    • }
    • // isEven(2);
    • // Previous iteration
    • // isEven = number => number %2 === 0 ?
    • // true: number %1 === 0 ?
    • // false : undefined;