Javascript map,filter,reduce tutorial

<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<title>Backbone & Handlebars Workshop</title>
</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;
});

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

var sum = numbers.reduce(function(o,n){
return o+n;
},0);
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