Git Product home page Git Product logo

manmaru.numberutil's Introduction

MANMARU NUMBERUTIL JS

Inspired from CASA Lib / AS 2.0 (v.10/06/08) - Aaron Clinger, David Nelson

manmaru.numberutil.js :
Utilities for manipulating number.

isEqual(val1, val2, precision) ->
Determines if the two values are equal, with the option to define the precision
@param val1: A value to compare
@param val2: A value to compare
@param precision: The maximum amount the two values can differ and still be considered equal
@return Returns true the values are equal; otherwise false

min(val1, val2) ->
Evaluates val1 and val2 and returns the smaller value
Unlike Math.min this method will return the defined value if the other value is null or not a number
@param val1: A value to compare
@param val2: A value to compare
@return Returns the smallest value, or the value out of the two that is defined and valid

randomWithinRange(min, max) ->
Creates a random number within the defined range
@param min: The minimum value the random number can be
@param min: The maximum value the random number can be
@return Returns a random number within the range

randomIntegerWithinRange(min, max) ->
Creates a random integer within the defined range
@param min: The minimum value the random integer can be
@param min: The maximum value the random integer can be
@return Returns a random integer within the range

isEven(value) ->
Determines if the number is even
@param value: A number to determine if it is divisible by 2
@return Returns true if the number is even; otherwise false

isOdd(value) ->
Determines if the number is odd
@param value: A number to determine if it is not divisible by 2
@return Returns true if the number is odd; otherwise false

addLeadingZero(value) ->
Adds a leading zero for numbers less than ten
@param value: Number to add leading zero
@return Number as a String; if the number was less than ten the number will have a leading zero

isInteger(value) ->
Determines if the number is an integer
@param value: A number to determine if it contains no decimal values
@return Returns true if the number is an integer; otherwise false

isPrime(value) ->
Determines if the number is prime
@param value: A number to determine if it is only divisible by 1 and itself
@return Returns true if the number is prime; otherwise false

roundDecimalToPlace(value, place) ->
Rounds a number's decimal value to a specific place
@param value: The number to round
@param place: The decimal place to round
@return Returns the value rounded to the defined place

NumberUtil.roundToPlace(3.14159, 2)); // 3.14
NumberUtil.roundToPlace(3.14159, 3)); // 3.142

isBetween(value, firstValue, secondValue) ->
Determines if the value is included within a range
@param value: Number to determine if it is included in the range
@param firstValue: First value of the range
@param secondValue: Second value of the range
@return Returns true if the number falls within the range; otherwise false
@usageNote The range values do not need to be in order.

NumberUtil.isBetween(3, 0, 5)); // true
(NumberUtil.isBetween(7, 0, 5)); // false

manmaru.numberutil's People

Contributors

adrien-dufond avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.