
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Reverse index value sum of array in JavaScript
Suppose we have an array of numbers like this −
const arr = [3, 6, 7, 3, 1, 4, 4, 3, 6, 7];
This array in the example contains 10 elements, so the index of last element happens to be 9. We are required to write a function that takes in one such array and returns the reverse index multiplied sum of the elements.
Like in this example, it would be something like −
(9*3)+(8*6)+(7*7)+(6*3)+.... until the end of the array.
Therefore, let's write the code for this function −
Example
const arr = [3, 6, 7, 3, 1, 4, 4, 3, 6, 7]; const reverseMultiSum = arr => { return arr.reduce((acc, val, ind) => { const sum = val * (arr.length - ind - 1); return acc + sum; }, 0); }; console.log(reverseMultiSum(arr));
Output
The output in the console will be −
187
- Related Articles
- Reverse sum array JavaScript
- Reverse sum of two arrays in JavaScript
- JavaScript to push value in empty index in array
- Array reverse() in JavaScript
- Sum all duplicate value in array - JavaScript
- JavaScript Array reverse()
- Even index sum in JavaScript
- How to sum elements at the same index in array of arrays into a single array? JavaScript
- Returning reverse array of integers using JavaScript
- Find closest index of array in JavaScript
- Finding median index of array in JavaScript
- Reverse Subarray To Maximize Array Value in C++
- Cumulative sum at each index in JavaScript
- Find sum of two array elements index wise in Java
- Sort by index of an array in JavaScript

Advertisements