Perimeter of squares in a rectangle

    0

    0

    YusifHasanov

    Perimeter is a function that calculates the circumference of a circle. It takes an integer n as an input and returns the value 4*fib.reduce((a, b) => a + b). fib is an array of numbers that represent Fibonacci numbers. Each number in the array is the result of the addition of the two preceding numbers in the Fibonacci sequence. The code first initializes an array called fib with the values 0, 1, 1, 2, 3, 5, 8, 13, 21. Then, it loops through the input value of n and creates a new Fibonacci number for each i value from 2 to n+1. Finally, the perimeter function calculates the circumference of the circle using the values in fib.

    function perimeter(n) {
    
      var fib = [0, 1];
      for (let i = 2; i <= n + 1; i++) {
        fib[i] = fib[i - 2] + fib[i - 1];
      }
    
      return 4 * fib.reduce((a, b) => a + b);
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.