You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+33-4Lines changed: 33 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,18 +19,47 @@ For use in the browser, use [browserify](https://github.com/substack/node-browse
19
19
To use the module,
20
20
21
21
```javascript
22
-
varfoo=require( 'compute-isnumeric' );
22
+
varisnumeric=require( 'compute-isnumeric' );
23
23
```
24
24
25
-
#### foo( arr )
25
+
#### isnumeric( arr )
26
26
27
-
What does this function do?
27
+
Computes for each `array` element whether an element is numeric. The function returns an `array` with length equal to that of the input `array`. Each output `array` element is either `0` or `1`. A value of `1` means that an element is numeric and `0` means that an element is __not__ numeric.
28
+
29
+
```javascript
30
+
var out =isnumeric( [ 5, 1/0, 'beep', 3, 9, NaN, true ] );
31
+
// returns [ 1, 1, 0, 1, 1, 0, 0 ]
32
+
```
28
33
29
34
30
35
## Examples
31
36
32
37
```javascript
33
-
var foo =require( 'compute-isnumeric' );
38
+
var isnumeric =require( 'compute-isnumeric' );
39
+
40
+
// Simulate some data...
41
+
var data =newArray( 100 ),
42
+
len =data.length,
43
+
rand;
44
+
45
+
// Every so often include a non-numeric value...
46
+
for ( var i =0; i < len; i++ ) {
47
+
rand =Math.random()*10;
48
+
if ( rand <0.5 ) {
49
+
rand =null;
50
+
}
51
+
data[ i ] = rand;
52
+
}
53
+
54
+
var out =isnumeric( data );
55
+
56
+
// Count the number of numeric values detected...
57
+
var sum =0;
58
+
for ( var i =0; i < len; i++ ) {
59
+
sum += out[ i ];
60
+
}
61
+
62
+
console.log( 'Count: %d', sum );
34
63
```
35
64
36
65
To run the example code from the top-level application directory,
0 commit comments