
- 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
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 Articles
- C program to find maximum of four integers by defining function
- Maximum array sum that can be obtained after exactly k changes in C++
- Find the largest interval that contains exactly one of the given N integers In C++
- Function that returns the minimum and maximum value of an array in JavaScript
- Maximum possible time that can be formed from four digits in C++
- Summing all the unique values of an array - JavaScript
- Return the minimum value that can be represented by the dtype of an object in Numpy
- Program to find maximum number of package that can be bought by buyers in C++
- Find integers that divides maximum number of elements of the array in C++
- Return the maximum value that can be represented by the dtype of an object in Numpy
- How to find the minimum and maximum values in a single MySQL Query?
- How to find the minimum and maximum of columns values in an R data frame?
- Summing up unique array values in JavaScript
- When summing values from 2 arrays how can I cap the value in the new JavaScript array?
- Build Array Where You Can Find The Maximum Exactly K Comparisons in C++

Advertisements