Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimum number excluding zero

Tags:

javascript

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)

like image 843
Ωmega Avatar asked May 11 '12 19:05

Ωmega


People also ask

How do you find the minimum value of an excluding zero?

Find minimum value excluding zero with formula Please apply the following formula to get the minimum value in that range excluding zero in Excel. 1. Select a blank cell (H1) for placing the minimum value, enter formula =SMALL(A1:E7,COUNTIF($A$1:$E$7,0)+1) into the Formula Bar, and then press the Enter key.


1 Answers

How about this?

var arry = [213, 0, 32, 92, 0, 2992, 39];
Math.min.apply(Math, arry.filter(Number)); // => 32
like image 200
jesal Avatar answered Sep 24 '22 17:09

jesal