beautifulDays.js

    0

    0

    The beautifulDays function takes three arguments, an integer starting at 1, a number starting at 1, and a number ending at 2. It creates an array called beautiful, and loops through each of the numbers starting at 1 and going up to and including the number ending at 2. At each loop, it creates a variable called numString and sets it to the string consisting of the number starting at 1 followed by a space and the number ending at 2. Then, it sets the variable reverse to the reverse of numString, which is the string made up of the number starting at 2 followed by a space and the number ending at 1. Finally, it adds the string "1" to the end of reverse and stores it in the variable start.

    The beautifulDays function will then return the length of the beautiful array, which in this case is 3.

    function beautifulDays(i, j, k) {
      let beautiful = [];
    for(let start = i; start <= j; start++){
    let numString = start+"";
        let reverse = numString.split('').reverse().join('');
    if((start - reverse*1) % k === 0){
          beautiful.push(start)
        }
      }
      return beautiful.length;
    }
    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.