Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than 32 bit integer.)
- Sample Input
- 1 2 3 4 5
- Sample Output
- 10 14*/
- function miniMaxSum(arr) {
- const maxAndMin = arr.reduce((newArr, n, index) => {
- return newArr.concat(arr.filter((num, ind) => index !== ind).reduce((total, curr) => total += curr, 0));
- }, []).reduce((maxAndMin, n, index) => {
- index === 0 ? (maxAndMin.max = n, maxAndMin.min = n) : null;
- n > maxAndMin.max ? maxAndMin.max = n : null;
- n < maxAndMin.min ? maxAndMin.min = n : null;
- return maxAndMin;
- }, {min: null, max: null});
- console.log(`${maxAndMin.min} ${maxAndMin.max}`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement