javascript map filter reduce example

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
</head>
<body>

http://js/lodash.min.js
http://js/handlebars.min.js
http://js/jquery.min.js
http://js/backbone-min.js

var numbers = [1,2,3,4,5];
var snumbers = numbers.map(function(i){
return i*i;
});

// it works like a loop ,return 1 4 9 16 25

var enumbers = numbers.filter(function(i){
return i%2==1;
});

//return 1 3 5

var sum = numbers.reduce(function(o,n){
return o+n;
},0);

//return  Total summation
console.log(sum);

</body>
</html>

 

 

Advertisements

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