

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Find the minimum and maximum values that can be calculated by summing exactly four of the five integers in JavaScript
Given an array of five positive integers, we are required to find the minimum and maximum values that can be calculated by summing exactly four of the five integers.
Then print the respective minimum and maximum values as a single line of two spaceseparated long integers.
The array is not sorted all the times.
For example −
const arr = [1, 3, 5, 7, 9]
The minimum sum is −
1 + 3 + 5 + 7 = 16
and the maximum sum is −
3 + 5 + 7 = 24
The return value of the function should be −
[16, 24];
Example
The code for this will be −
const arr = [1, 3, 5, 7, 9] const findMinMaxSum = (arr = []) => { let numbers = arr.slice().sort(); let maxScore = 0; let minScore = 0; for(let i = 0; i < numbers.length − 1; i++) { minScore += numbers[i]; }; for(let j = 1; j < numbers.length; j++) { maxScore += numbers[j]; }; return [minScore, maxScore]; }; console.log(findMinMaxSum(arr));
Output
And the output in the console will be −
[16, 24]
- Related Questions & Answers
- C program to find maximum of four integers by defining function
- Find the largest interval that contains exactly one of the given N integers In C++
- Maximum possible time that can be formed from four digits in C++
- Maximum array sum that can be obtained after exactly k changes in C++
- Return the minimum value that can be represented by the dtype of an object in Numpy
- Return the maximum value that can be represented by the dtype of an object in Numpy
- Find integers that divides maximum number of elements of the array in C++
- Function that returns the minimum and maximum value of an array in JavaScript
- Program to find maximum number of package that can be bought by buyers in C++
- Summing all the unique values of an array - JavaScript
- C++ program to find out the maximum number of cells that can be illuminated
- Problem to Find Out the Maximum Number of Coins that Can be Collected in Python
- How to find the minimum and maximum values in a single MySQL Query?
- Build Array Where You Can Find The Maximum Exactly K Comparisons in C++
- How to find the minimum and maximum of columns values in an R data frame?
Advertisements