Skip to content

Instantly share code, notes, and snippets.

@Viktorminator
Created October 17, 2016 19:22
Show Gist options
  • Save Viktorminator/8d94375baecc6b1ca7da6e1a12bfba53 to your computer and use it in GitHub Desktop.
Save Viktorminator/8d94375baecc6b1ca7da6e1a12bfba53 to your computer and use it in GitHub Desktop.
Sum without highest and lowest number
const sumArray = arr => ((arr == null) || (arr.length < 2)) ? 0 : arr.reduce((a, b) => a + b, 0) - Math.max(...arr) - Math.min(...arr);
@Viktorminator
Copy link
Author

best

sumArray = a => a ? a.sort((x, y) => x - y).slice(1, -1).reduce((s, e) => s + e, 0) : 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment