RightJS extends the Number unit in order to make it support the Math module methods in a more natural, object-oriented way. And it adds the handy Ruby style loop methods as well.
include, abs, ceil, downto, floor, round, times, upto
Number.include(Object new_methods[, Boolean dont_overwrite) -> Number
Registers new functionality for Number instances
If the second argument is true, then the method will skip already existing methods
Number.include({
double: function() {
return this * 2;
}
});
2..double(); // -> 4
abs() -> number absolute value
Returns the absolute value of the number.
-1..abs(); // -> 1
22..abs(); // -> 22
ceil() -> number
Returns the smallest integer bigger than or equal to the current number.
2.2.ceil(); // -> 3
downto(number end, Function lambda[, Object scope]) -> number self
Iterates the given lambda function from the current number down to the given stop number:
var numbers = [];
8..downto(4, function(i) {
numbers.push(i);
});
numbers; // [8,7,6,5,4]
floor() -> number
Returns the biggest integer smaller than or equal to the current number.
2.2.floor(); // -> 2
round([Integer base]) -> number
Returns the integer number closest to the current number. The optional argument specifies how many digits after the decimal point should be retained.
2.2.round(); // -> 2
8.8.round(); // -> 8
4.444.round(1); // -> 4.4
4.444.round(2); // -> 4.44
4.444.round(3); // -> 4.444