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

The following PHP extension is missing: curl AMP WordPress

January 16, 2020 beroza

How to sort an array of objects in JavaScript?

April 10, 2021 beroza

Reasons of timeout when trying to connect EC2 instance.

January 13, 2020 beroza

In which order static initialisation block and constructor run in java?

September 16, 2019 beroza

apache2.service failed “systemctl status apache2.service” and “journalctl -xe” for details

November 13, 2019 beroza

Crop long string using a given limit in JavaScript

February 12, 2022 beroza

JavaScript Primitive vs. Reference Types

August 27, 2021 beroza

Write a Program to Find Third Maximum Number

March 1, 2023 beroza

Find total number of Sundays between two dates in JavaScript

December 22, 2018 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.