Traversing by jstraverse

traverse and transform object by recursive walk.

for transforming negative numbers.

var Traverse = require('traverse');
var obj = [ 5, 6, -3, [ 7, 8, -2, 1 ], { f : 10, g : -13 } ];

Traverse(obj).forEach(function (x) {
 console.log(x);
 if (x < 0) this.update(x + 128);
});

console.dir(obj);

gives the output by putting console.log(x)

[ 5, 6, -3, [ 7, 8, -2, 1 ], { f: 10, g: -13 } ]
5
6
-3
[ 7, 8, -2, 1 ]
7
8
-2
1
{ f: 10, g: -13 }
10
-13
[ 5, 6, 125, [ 7, 8, 126, 1 ], { f: 10, g: 115 } ]
Advertisements

About rahul23134654

Hi, I am Rahul Meha , B.E. in (I.T.)
This entry was posted in Node.js. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s