I see your single purpose reduce and raise you a reduce that does a bunch of stuff (just for fun).
reduce
const add = (a, b) => a + b; const print = ([a, b]) => console.log(`${a} ${b}`); const repeat = (num, item) => Array.from({ length: num }, () => item); const three_ops = ([first, ...rest]) => rest.reduce( (state, value) => [ state[0], Math.max(state[0], value), Math.min(state[0], value), add(state[3], value) ], repeat(4, first) ); function miniMaxSum(arr) { const [,max,min,sum] = three_ops(arr); return [ sum - max, sum - min ]; } print(miniMaxSum([1,3,5,7,9]));
Kids, don't do this at home.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I see your single purpose
reduce
and raise you areduce
that does a bunch of stuff (just for fun).Kids, don't do this at home.