mirror of
https://github.com/flynx/walk.js.git
synced 2025-10-29 19:10:11 +00:00
added *ignore stuff
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d610447daa
commit
d02a5f6053
4
.gitignore
vendored
Normal file
4
.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
.*
|
||||||
|
*.sw[po]
|
||||||
|
*.vim
|
||||||
|
node_modules/*
|
||||||
5
.npmignore
Normal file
5
.npmignore
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
.npm*
|
||||||
|
*.vim
|
||||||
|
*.sw[po]
|
||||||
|
.git
|
||||||
|
npm-debug.log
|
||||||
13
README.md
13
README.md
@ -43,19 +43,32 @@ Target use-cases:
|
|||||||
|
|
||||||
sum( [1, [2, 3], 4, [[5], 6]] ) // -> 21
|
sum( [1, [2, 3], 4, [[5], 6]] ) // -> 21
|
||||||
```
|
```
|
||||||
|
For reference here is a *recursive* `.reduce(..)` example:
|
||||||
|
```javascript
|
||||||
|
function sumr(l){
|
||||||
|
return l.reduce(function(r, e){
|
||||||
|
return r + (e instanceof Array ?
|
||||||
|
sumr(e)
|
||||||
|
: e) }, 0) }
|
||||||
|
|
||||||
|
sumr( [1, [2, 3], 4, [[5], 6]] ) // -> 21
|
||||||
|
```
|
||||||
- Need to abort the recursion prematurelly:
|
- Need to abort the recursion prematurelly:
|
||||||
```javascript
|
```javascript
|
||||||
|
// check if structure contains 0...
|
||||||
var containsZero = walk(function(r, e, next, down, stop){
|
var containsZero = walk(function(r, e, next, down, stop){
|
||||||
return e === 0 ?
|
return e === 0 ?
|
||||||
// target found, abort the search...
|
// target found, abort the search...
|
||||||
stop(true)
|
stop(true)
|
||||||
: e instanceof Array ?
|
: e instanceof Array ?
|
||||||
|
// breadth-first walk...
|
||||||
!!next(...e)
|
!!next(...e)
|
||||||
: r }, false)
|
: r }, false)
|
||||||
|
|
||||||
containsZero( [1, [2, 0], 4, [[5], 6]] ) // -> true
|
containsZero( [1, [2, 0], 4, [[5], 6]] ) // -> true
|
||||||
containsZero( [1, [2, 5], 4, [[5], 6]] ) // -> false
|
containsZero( [1, [2, 5], 4, [[5], 6]] ) // -> false
|
||||||
```
|
```
|
||||||
|
See a more usefull search in [examples](#examples)...
|
||||||
|
|
||||||
|
|
||||||
## Installation and loading
|
## Installation and loading
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user