This code arranges coins into a numeric array. It creates a new variable called copy and sets it to the value of the parameter, n. It then starts counting from the beginning of the value of copy. If the value of copy is less than zero, then it increments the value of count by one. If the value of copy is greater than or equal to zero, then it decreases the value of count by one. When copy reaches 0, then the code returns the value of count.

    const arrangeCoins = (n) => {
      let copy = n, count = 0;
      while (copy > 0) {
        if (copy - count > 0)
          count += 1;
        copy -= count;
      return count;
    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.