Skip to content

Commit

Permalink
fixed... er, changed numbers example (still working out private stuff)
Browse files Browse the repository at this point in the history
  • Loading branch information
dtao committed Dec 30, 2013
1 parent 0078298 commit a24bcc5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Now we can also use Autodoc to quickly race these two implementations against on

![Benchmarks screenshot](http://breakneck.danieltao.com/images/benchmarks_screenshot.png)

All righty. Let's say we're completely delusional and actually think this library is useful, so we want to share it with the world. We'll add some simple comments describing what each function does and wrap the library up in a semi-reasonable way so it runs in either Node or the browser:
All righty. Let's say we're completely delusional and actually think this library is useful, so we want to share it with the world. We'll add some simple comments describing what each function does, remove the `@private` tags, and wrap the library up in a semi-reasonable way so it runs in either Node or the browser:

```javascript
/**
Expand Down
32 changes: 26 additions & 6 deletions example/numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
*/
(function(Numbers) {

/**
* @private
* @examples
* isInteger(5) // => true
* isInteger(5.0) // => true
* isInteger(-5) // => true
* isInteger(3.14) // => false
* isInteger('foo') // => false
* isInteger(NaN) // => false
*/
function isInteger(x) {
return x === Math.floor(x);
}

/**
* Checks if a number is an integer. Returns false for anything that isn't an
* integer, including non-numbers.
*
* @private
*
* @examples
* Numbers.isInteger(5) // => true
* Numbers.isInteger(5.0) // => true
Expand All @@ -18,15 +30,23 @@
* Numbers.isInteger(NaN) // => false
*/
Numbers.isInteger = function(x) {
return x === Math.floor(x);
return isInteger(x);
};

/**
* @private
* @examples
* isIntegerLike(123) // => true
* isIntegerLike(3.14) // => false
*/
function isIntegerLike(x) {
return (/^\d+$/).test(String(x));
}

/**
* Checks if a value looks like an integer. Returns true for both integers and
* strings that represent integers, false for everything else.
*
* @private
*
* @examples
* Numbers.isIntegerLike(123) // => true
* Numbers.isIntegerLike(3.14) // => false
Expand All @@ -36,7 +56,7 @@
* Numbers.isIntegerLike(123456789) // using RegExp: ^\d+$
*/
Numbers.isIntegerLike = function(x) {
return (/^\d+$/).test(String(x));
return isIntegerLike(x);
};

}(typeof module === 'object' ? (module.exports = {}) : (this.Numbers = {})));

0 comments on commit a24bcc5

Please sign in to comment.