Ad
Code
Diff
  • isEven = n => Number.isInteger(n)? !(n%2) : undefined;
    
    • 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;
    • // }
    • isEven = n => Number.isInteger(n)? !(n%2) : undefined;
Mathematics

Iterative approach to calculate Fibonacci number, the iterative approach is more optimized than the recursive approach for calculating the Fibonacci. This is because the iterative approach requires only a constant amount of memory for storing the two variables "a" and "b", whereas the recursive approach requires a large amount of memory for storing the intermediate results of each recursive call on the call stack.

Code
Diff
  • const fibonacci = (n) => {
      let [a,b] = [0,1];
      
      for(let i=0;i<n;i++){
        [a,b] = [b,b+a];
      }
      
      return a;
    }
    • function fibonacci(n) {
    • if (n <= 1) return n;
    • return fibonacci(n - 1) + fibonacci(n - 2);
    • const fibonacci = (n) => {
    • let [a,b] = [0,1];
    • for(let i=0;i<n;i++){
    • [a,b] = [b,b+a];
    • }
    • return a;
    • }