beautifulArray.js

    0

    0

    This code constructs an array of numbers and checks to see if the array is "beautiful" by comparing the length of each element with the range of numbers provided. The function isBeautifulArray compares the length of the array elements against a provided range, and returns a boolean value.

    function arrayConstructor(paramsArray, number2, params2Number) {
      while (number2 <= params2Number) {
        if (number2 <= params2Number) {
          paramsArray.push(number2);
        } else {
          break;
        }
      
        number2 *= 2;
      }
      
      return paramsArray;
    }
      
    function isBeautifulArray(paramsNumber) {
      let initialArray = [];
      
      arrayConstructor([], 1, paramsNumber).forEach((item) => {
        `${item}`.split("").forEach((item2) => {
          initialArray.push(item2);
        });
      });
      
      let isBeauty = true;
      
      initialArray.forEach((item, index, arraySelf) => {
        if (arraySelf.indexOf(item) !== arraySelf.lastIndexOf(item)) {
          isBeauty = false;
        }
      });
      
      console.log(initialArray);
      console.log(isBeauty);
      
      return parseInt(isBeauty);
    }
      
    isBeautifulArray(16);
    
    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.