Skip to content

Instantly share code, notes, and snippets.

Created May 3, 2016 13:00
Show Gist options
  • Select an option

  • Save anonymous/a2045bbaeb355e0c3f09cfb6aab1d6f8 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/a2045bbaeb355e0c3f09cfb6aab1d6f8 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/yazozum
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
//ForEach
"use strict";
[1, 2, 3].forEach(function (x) {
return console.log(x);
});
//Map
[1, 2, 3].map(function (x) {
return x + 1;
});
//Filter [returns a boolean,applying test to each elem]
[1, 2, 3].filter(function (x) {
return x > 1;
});
//concatAll [not in ES6]
[[1], [2, 3], [], [4]].concatAll(); //[1,2,3,4]
// Top-rated Movies Colleciton
var getTopRatedFilms = function getTopRatedFilms(user) {
return user.videoLists.map(function (videoList) {
return videoList.videos.filter(function (video) {
return video.rating === 5.0;
});
}).concatAll();
};
getTopRatedFilms(user).forEach(function (film) {
return console.log(film);
});
//Mouse Drags collection [Top-rated Movies Colleciton]
var getElementDrags = function getElementDrags(elmt) {
return elmt.mouseDowns.map(function (mouseDown) {
return document.mouseMoves.takeUntil(document.mouseUps);
}).concatAll();
};
getElementDrags(image).forEach(function (pos) {
return image.position = pos;
});
// Introducing Observable
Observable === Collections + Time;
</script>
<script id="jsbin-source-javascript" type="text/javascript">//ForEach
[1,2,3].forEach(x => console.log(x));
//Map
[1,2,3].map(x => x + 1);
//Filter [returns a boolean,applying test to each elem]
[1,2,3].filter(x => x > 1);
//concatAll [not in ES6]
[[1],[2,3],[],[4]].concatAll()//[1,2,3,4]
// Top-rated Movies Colleciton
var getTopRatedFilms = user =>
user.videoLists.
map(videoList =>
videoList.videos.
filter(video => video.rating === 5.0)).
concatAll();
getTopRatedFilms(user).
forEach(film => console.log(film));
//Mouse Drags collection [Top-rated Movies Colleciton]
var getElementDrags = elmt =>
elmt.mouseDowns.
map(mouseDown =>
document.mouseMoves.
takeUntil(document.mouseUps)).
concatAll();
getElementDrags(image).
forEach(pos => image.position = pos);
// Introducing Observable
Observable === Collections + Time
</script></body>
</html>
//ForEach
"use strict";
[1, 2, 3].forEach(function (x) {
return console.log(x);
});
//Map
[1, 2, 3].map(function (x) {
return x + 1;
});
//Filter [returns a boolean,applying test to each elem]
[1, 2, 3].filter(function (x) {
return x > 1;
});
//concatAll [not in ES6]
[[1], [2, 3], [], [4]].concatAll(); //[1,2,3,4]
// Top-rated Movies Colleciton
var getTopRatedFilms = function getTopRatedFilms(user) {
return user.videoLists.map(function (videoList) {
return videoList.videos.filter(function (video) {
return video.rating === 5.0;
});
}).concatAll();
};
getTopRatedFilms(user).forEach(function (film) {
return console.log(film);
});
//Mouse Drags collection [Top-rated Movies Colleciton]
var getElementDrags = function getElementDrags(elmt) {
return elmt.mouseDowns.map(function (mouseDown) {
return document.mouseMoves.takeUntil(document.mouseUps);
}).concatAll();
};
getElementDrags(image).forEach(function (pos) {
return image.position = pos;
});
// Introducing Observable
Observable === Collections + Time;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment