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);
      
      Typescript language logo

      Sum of powers

      Codiga's TypeScript Recipes

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

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.