Skip to content

Instantly share code, notes, and snippets.

@tdlm
Created February 18, 2017 23:40
Show Gist options
  • Save tdlm/56c230879ae9b4d98d1d13ed2b3dce23 to your computer and use it in GitHub Desktop.
Save tdlm/56c230879ae9b4d98d1d13ed2b3dce23 to your computer and use it in GitHub Desktop.
const sumArray = (a) => {
if ( typeof a == 'undefined' || !a || a.length < 2 ) { return 0; }
a.sort((a,b) => a - b).splice(0, 1)
a.splice(a.length - 1, 1);
if ( a.length < 3 ) { return 0; }
return a.reduce((a,b) => a+b);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment