- 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
Summing cubes of natural numbers within a range in JavaScript
Problem
We are required to write a JavaScript function that takes in a range array of two numbers. Our function should find the sum of all the cubes of the numbers that falls in the specified range.
Example
Following is the code −
const range = [4, 11]; const sumCubes = ([l, h]) => { const findCube = num => num * num * num; let sum = 0; for(let i = l; i <= h; i++){ sum += findCube(i); }; return sum; }; console.log(sumCubes(range));
Output
4320
- Related Articles
- Prime numbers within a range in JavaScript
- Finding sum of all numbers within a range in JavaScript
- Returning array of natural numbers between a range in JavaScript
- Finding sequential digit numbers within a range in JavaScript
- Summing numbers from a string - JavaScript
- Write the cubes of all natural numbers between 1 and 10 and verify the following statements:(i) Cubes of all odd natural numbers are odd.(ii) Cubes of all even natural numbers are even.
- Finding the count of numbers divisible by a number within a range using JavaScript
- Summing array of string numbers using JavaScript
- Armstrong number within a range in JavaScript
- Counting prime numbers that reduce to 1 within a range using JavaScript
- Python - Find the number of prime numbers within a given range of numbers
- JavaScript - summing numbers from strings nested in array
- Generating desired pairs within a range using JavaScript
- Summing numbers present in a string separated by spaces using JavaScript
- Golang Program to Print Odd Numbers Within a Given Range

Advertisements