Friday, June 20, 2025
Latest:
  • German Pronouns with Nominative, Accusative, and Dative cases
  • German articles for the nominative, accusative, and dative cases
  • Der kleine Vogel und die Sonne
  • German alphabet pronunciation
  • Command design pattern
Upokary

Upokary

Quality information

  • Health
  • Life
  • Fashion
  • Food
  • Code
  • English
  • বাংলা
Technology 

Calculate the sum of numbers from 1 to n using recursion

Published: June 17, 2023code, program, programming, programming tips, recursion
(function(){
    // Calculate the sum of numbers from 1 to n using recursion.

    const getSum = (arr) => {
       if (arr.length < 1) {
          return 0;
       }

       return arr.pop() + getSum(arr);
    };
 
    const a = [1, 2, 3, 5];
    console.log(getSum(a))
})();

You May Also Like

How to get JavaScript fetch http response status?

March 2, 2020 beroza

How to pass an event to parent DOM from Iframe using JavaScript?

November 29, 2020 beroza

Override clone judiciously in java

February 5, 2020 beroza

Find First and Last Position of Element in Sorted Array

January 29, 2023 beroza

How to use setInterval efficiently in JavaScript?

October 27, 2021 beroza

Adapter design pattern

February 19, 2023 beroza

CSS special selectors

August 26, 2021 beroza

Useful command that developers should know

July 31, 2019 beroza

How to set custom user-agent in Google chrome?

June 1, 2020 beroza

Why Upokary?

Upokary.com is a useful application in everyday life. It provides very handy information regarding every aspect of life. Each and every tip of upokary.com is meant to make life better.

Upokary tools

  • Youtube thumbnail
  • Youtube video downloader

Useful Links

  • Handy code
  • Technology
  • People
  • Programming
  • Quote
  • Travel
  • WordPress
  • IELTS
  • Kids

Languages

  • EnglishEnglish
  • বাংলাবাংলা

Pages

  • Sitemap
  • Privacy policy
  • About us
  • Contact us

Support

For any kind of query or question please drop a message in the following email: upokary@gmail.com
Copyright © 2025 Upokary. All rights reserved.