Created
January 2, 2019 12:49
-
-
Save kharioki/263be25c44a73f9dddcb54c49e4ed189 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| process.stdin.resume(); | |
| process.stdin.setEncoding('utf-8'); | |
| let inputString = ''; | |
| let currentLine = 0; | |
| process.stdin.on('data', inputStdin => { | |
| inputString += inputStdin; | |
| }); | |
| process.stdin.on('end', _ => { | |
| inputString = inputString.replace(/\s*$/, '') | |
| .split('\n') | |
| .map(str => str.replace(/\s*$/, '')); | |
| main(); | |
| }); | |
| function readLine() { | |
| return inputString[currentLine++]; | |
| } | |
| // Complete the miniMaxSum function below. | |
| function miniMaxSum(arr) { | |
| arr.sort((a, b) => a - b) | |
| let first = arr.slice(0, -1); | |
| let last = arr.slice(1) | |
| let minSum = first.reduce((a, b) => a + b, 0); | |
| let maxSum = last.reduce((a, b) => a + b, 0); | |
| console.log(minSum + " " + maxSum) | |
| } | |
| function main() { | |
| const arr = readLine().split(' ').map(arrTemp => parseInt(arrTemp, 10)); | |
| miniMaxSum(arr); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment