Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
14 changes: 14 additions & 0 deletions .jshintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Directories #
###############
build/
reports/
dist/

# Node.js #
###########
/node_modules/

# Git #
#######
.git*
71 changes: 71 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"bitwise": false,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"es3": false,
"forin": true,
"freeze": true,
"immed": true,
"indent": 4,
"latedef": "nofunc",
"newcap": true,
"noarg": true,
"noempty": false,
"nonbsp": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"undef": true,
"unused": true,
"strict": true,
"maxparams": 10,
"maxdepth": 5,
"maxstatements": 100,
"maxcomplexity": false,
"maxlen": 1000,
"asi": false,
"boss": false,
"debug": false,
"eqnull": false,
"esnext": false,
"evil": false,
"expr": false,
"funcscope": false,
"globalstrict": false,
"iterator": false,
"lastsemic": false,
"laxbreak": false,
"laxcomma": false,
"loopfunc": false,
"maxerr": 1000,
"moz": false,
"multistr": false,
"notypeof": false,
"proto": false,
"scripturl": false,
"shadow": false,
"sub": true,
"supernew": false,
"validthis": false,
"noyield": false,
"browser": true,
"browserify": true,
"couch": false,
"devel": true,
"dojo": false,
"jasmine": false,
"jquery": false,
"mocha": true,
"mootools": false,
"node": true,
"nonstandard": false,
"prototypejs": false,
"qunit": false,
"rhino": false,
"shelljs": false,
"worker": false,
"wsh": false,
"yui": false,
"globals": {}
}
5 changes: 4 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ examples/
reports/
support/
test/
benchmark/

# Node.js #
###########
Expand Down Expand Up @@ -46,4 +47,6 @@ Desktop.ini
# Utilities #
#############
.jshintrc
.travis.yml
.jshintignore
.travis.yml
.editorconfig
11 changes: 9 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
language: node_js
node_js:
- "0.10"
- '0.12'
- '0.11'
- '0.10'
- '0.8'
- 'iojs'
before_install:
- npm update -g npm
after_script:
- npm run coveralls
- npm run coveralls

4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 Athan Reines.
Copyright (c) 2014-2015 Athan Reines.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
28 changes: 21 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,31 @@ NODE_ENV ?= test

# NOTES #

NOTES ?= 'TODO|FIXME'
NOTES ?= 'TODO|FIXME|WARNING|HACK|NOTE'


# MOCHA #

# Specify the test framework bin locations:
MOCHA ?= ./node_modules/.bin/mocha
_MOCHA ?= ./node_modules/.bin/_mocha

# Specify the mocha reporter:
MOCHA_REPORTER ?= spec


# ISTANBUL #

# Istanbul configuration:
ISTANBUL ?= ./node_modules/.bin/istanbul
ISTANBUL_OUT ?= ./reports/coverage
ISTANBUL_REPORT ?= lcov
ISTANBUL_LCOV_INFO_PATH ?= $(ISTANBUL_OUT)/lcov.info
ISTANBUL_HTML_REPORT_PATH ?= $(ISTANBUL_OUT)/lcov-report/index.html


# JSHINT #

JSHINT ?= ./node_modules/.bin/jshint
JSHINT_REPORTER ?= ./node_modules/jshint-stylish/stylish.js



# FILES #

Expand Down Expand Up @@ -81,7 +83,8 @@ test-istanbul-mocha: node_modules
NODE_ENV=$(NODE_ENV) \
NODE_PATH=$(NODE_PATH_TEST) \
$(ISTANBUL) cover \
--dir $(ISTANBUL_OUT) --report $(ISTANBUL_REPORT) \
--dir $(ISTANBUL_OUT) \
--report $(ISTANBUL_REPORT) \
$(_MOCHA) -- \
--reporter $(MOCHA_REPORTER) \
$(TESTS)
Expand All @@ -99,6 +102,18 @@ view-istanbul-report:



# LINT #

.PHONY: lint lint-jshint

lint: lint-jshint

lint-jshint: node_modules
$(JSHINT) \
--reporter $(JSHINT_REPORTER) \
./


# NODE #

# Installing node_modules:
Expand All @@ -116,7 +131,6 @@ clean-node:


# CLEAN #

.PHONY: clean

clean:
Expand Down
85 changes: 62 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ signum
===
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependencies][dependencies-image]][dependencies-url]

> Signum function.
> [Signum](http://en.wikipedia.org/wiki/Sign_function) function.


## Installation
Expand All @@ -16,44 +16,61 @@ For use in the browser, use [browserify](https://github.com/substack/node-browse

## Usage

To use the module,

``` javascript
var signum = require( 'compute-signum' );
```

#### signum( x )
#### signum( x[, options] )

Evaluates the signum function. The method accepts a single argument: either a single `numeric` value or an `array` of numeric values, which may include `NaN`, `+infinity`, and `-infinity`. For an input `array`, the signum function is evaluated for each value.
Evaluates the [signum](http://en.wikipedia.org/wiki/Sign_function) function. The method accepts as its first argument either a single `numeric` value or an `array` of numeric values, which may include `NaN`, `+infinity`, and `-infinity`. For an input `array`, the [signum](http://en.wikipedia.org/wiki/Sign_function) function is evaluated for each value.

``` javascript
signum( -10 );
var sgn = signum( -10 );
// returns -1

signum( [ -10, -1, -0, 0, 1, 10 ] );
// returns [...]
var sgns = signum( [ -10, -1, -0, 0, 1, 10 ] );
// returns [ -1, -1, 0, 0, 1, 1 ]
```

When provided an input `array`, the function accepts two `options`:

## Examples
* __copy__: `boolean` indicating whether to return a new `array` containing the signum values. Default: `true`.
* __accessor__: accessor `function` for accessing numeric values in object `arrays`.

To mutate the input `array` (e.g. when input values can be discarded or when optimizing memory usage), set the `copy` option to `false`.

``` javascript
var signum = require( 'compute-signum' );
var arr = [ -10, -1, -0, 0, 1, 10 ];

var data = new Array( 100 );
for ( var i = 0; i < data.length; i++ ) {
data[ i ] = Math.random() - 0.5;
}
var sgns = signum( arr );
// returns [ -1, -1, -0, 0, 1, 1 ]

console.log( signum( data ) );
console.log( arr === sgns );
// returns true
```

To run the example code from the top-level application directory,
For object `arrays`, provide an accessor `function` for accessing `array` values.

``` bash
$ node ./examples/index.js
``` javascript
var data = [
['beep', -10],
['boop', -1],
['bap', 1],
['baz', 10]
];

function getValue( d, i ) {
return d[ 1 ];
}

var sgns = signum( data, getValue );
// returns [ -1, -1, 1, 1 ]
```

__Note__: the function returns an `array` with a length equal to the original input `array`.




## Notes

Expand All @@ -70,11 +87,33 @@ Value | Sign
The above results are compatible with an ECMAScript 6 [proposal](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-math.sign) from Mozilla, which would extend the `Math` object to include the method `Math.sign()`. Currently, only [Mozilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign) implements this proposal.



## Examples

``` javascript
var signum = require( 'compute-signum' );

var data = new Array( 100 );
for ( var i = 0; i < data.length; i++ ) {
data[ i ] = Math.random() - 0.5;
}

console.log( signum( data ) );
```

To run the example code from the top-level application directory,

``` bash
$ node ./examples/index.js
```



## Tests

### Unit

Unit tests use the [Mocha](http://visionmedia.github.io/mocha) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory:
Unit tests use the [Mocha](http://mochajs.org) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory:

``` bash
$ make test
Expand All @@ -98,15 +137,15 @@ $ make view-cov
```


---
## License

[MIT license](http://opensource.org/licenses/MIT).
[MIT license](http://opensource.org/licenses/MIT).


---
## Copyright

Copyright &copy; 2014. Athan Reines.
Copyright &copy; 2014-2015. Athan Reines.


[npm-image]: http://img.shields.io/npm/v/compute-signum.svg
Expand All @@ -125,4 +164,4 @@ Copyright &copy; 2014. Athan Reines.
[dev-dependencies-url]: https://david-dm.org/dev/compute-io/signum

[github-issues-image]: http://img.shields.io/github/issues/compute-io/signum.svg
[github-issues-url]: https://github.com/compute-io/signum/issues
[github-issues-url]: https://github.com/compute-io/signum/issues
4 changes: 3 additions & 1 deletion examples/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';

var signum = require( './../lib' );

var data = new Array( 100 );
for ( var i = 0; i < data.length; i++ ) {
data[ i ] = Math.random() - 0.5;
}

console.log( signum( data ) );
console.log( signum( data ) );
Loading