Minimum number excluding zero
javascript
Solution
Code/Solution:
var arr = [3, 0, 7, 12, 0, 5, 22];
var minValue = Math.min.apply(null, arr.filter(Boolean));
How it works:
`arr.filter` creates a new array with all elements that pass the test implemented by the provided function. So in the code above each value of the array will be tested by `Boolean(value)`
Boolean(3) // true
Boolean(0) // false
Boolean(7) // true
// ...
So as a result we will have new filtered array with all elements except zeros.
Then `Math.min.apply(null, ...)` find min value in such array.
`null` is in this case a context. It can be `null`, `this`, `Math` - result will be the same.
Problem
I need to find minimum number from list of numbers, excluding zero(s). Is there some internal function that would do that? Or do I have to remove zero(s) from list before `Math.min` is used? Example: Input: `213`, `0`, `32`, `92`, `0`, `2992`, `39` Result: `32` [UPDATE] If possible, please provide code for function that would take inputs as arguments, such as `nonZeroMin(213, 0, 32, 92, 0, 2992, 39)`