Sum of powers

    0

    0

    Giovanny Gongora

    Codiga's TypeScript Recipes

    Calculates the sum of the powers of all the numbers from start to end (both inclusive).

    const sumPower = (end: number, power: number = 2, start: number = 1) =>
      Array(end + 1 - start)
        .fill(0)
        .map((x, i) => (i + start) ** power)
        .reduce((a, b) => a + b, 0);
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.