Wednesday, September 27, 2023
Latest:
  • Foods that eliminate liver cancer and liver fat.
  • Should we write a lot of code inside finally block?
  • Big O Notation
  • Heath benefits of raw jackfruit
  • Calculate the sum of numbers from 1 to n using recursion
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 resize SVG type image?

May 30, 2021 beroza

Next.js interview questions

December 16, 2021 beroza

How to get the selected text from a HTML document using JavaScript?

February 22, 2020 beroza

Find the missing number in the array using JavaScript.

February 10, 2022 beroza

What are the correct file permission for WordPress site?

January 9, 2020 beroza

Uncaught TypeError: render is not a function react-dom

July 5, 2019 beroza

What is JavaScript hoisting?

December 25, 2018 beroza

How to check the installed Ubuntu version?

May 7, 2020 beroza

How to get total days 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 © 2023 Upokary. All rights reserved.