Skip to content

Get the minimum of two numbers that works the way you would expect.

License

Notifications You must be signed in to change notification settings

nickpoorman/get-min

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

get-min

Get the minimum of two numbers that works the way you would expect.

It takes two anything and returns the lesser number of the two. Thats it.

example

var getMin = require('get-min');

getMin(0, 1); // 0
getMin('a', 1); // 1
getMin(1, null); // 1
getMin(1, undefined); // 1
getMin(1, Object(0)); // 1
getMin(1); // 1

getMin('1', '2'); // undefined
getMin('a', null); // undefined
getMin(); // undefined

why?

Getting the minimum of a number and garbage should be simple. It's a number that should be returned.

This example would normally require you to initialize num=10 if you were to use Math.min.

var num;

for (var i = 10; i >= 0; i--) {
  num = getMin(num, i);
};

// num = 0

vs.

var num;

for (var i = 10; i >= 0; i--) {
  num = Math.min(num, i);
};

// num = NaN   // whoops!

About

Get the minimum of two numbers that works the way you would expect.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published