- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Finding the sum of all numbers in the nth row of an increasing triangle using JavaScript
Increasing Triangle
For the purpose of this problem, suppose an increasing triangle to be like this −
1 2 3 4 5 6 7 8 9 10
Problem
We are required to write a JavaScript function that takes in a number n and returns the sum of numbers present in the nth row of increasing triangle.
Example
Following is the code −
const num = 15; const rowSum = (num = 1) => { const arr = []; const fillarray = () => { let num = 0; for(let i = 1; i <= 10000; i++){ const tempArr = []; for(let j = 0; j < i; j++){ num++; tempArr.push(num) }; arr.push(tempArr); }; }; fillarray() return arr[num-1].reduce((a, b)=>a + b, 0); }; console.log(rowSum(num));
Output
1695
- Related Articles
- Finding nth element of an increasing sequence using JavaScript
- Finding the elements of nth row of Pascal's triangle in JavaScript
- Finding the nth digit of natural numbers JavaScript
- Finding sum of all numbers within a range in JavaScript
- Finding sum of every nth element of array in JavaScript
- Finding nth element of the Padovan sequence using JavaScript
- Finding nth digit of natural numbers sequence in JavaScript
- Finding the sum of all common elements within arrays using JavaScript
- Finding the sum of minimum value in each row of a 2-D array using JavaScript
- Finding the nth power of array element present at nth index using JavaScript
- Finding lunar sum of Numbers - JavaScript
- Finding the nth palindrome number amongst whole numbers in JavaScript
- Sum of all prime numbers in an array - JavaScript
- Finding sum of all unique elements in JavaScript
- Finding sum of remaining numbers to reach target average using JavaScript

Advertisements