Skip to content

Instantly share code, notes, and snippets.

@rofrol
Forked from anonymous/index.html
Last active September 19, 2015 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rofrol/4c8434b94c1c9a6d9911 to your computer and use it in GitHub Desktop.
Save rofrol/4c8434b94c1c9a6d9911 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/yelaqa
<!DOCTYPE html>
<html>
<head>
<script src="http://fb.me/react-with-addons-0.13.3.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<h1>getTopRatedFilms()</h1>
<button onClick="getMovies()">getMovies</button>
<button onClick="clearMovies()">clearMovies</button>
<div id="movies"></div>
<script id="jsbin-javascript">
/*jshint esnext: true */
// Async Programming at Netflix by Matthew Podwysocki at Web Rebels 2015 https://vimeo.com/128858567
"use strict";
var user = {
videoLists: [{
name: "postapocalyptic",
videos: [{ name: "Mad Max", rating: 5 }, { name: "BlaBla", rating: 3 }]
}, {
name: "thriller",
videos: [{ name: "Nope", rating: 2 }, { name: "The girl with the dragon tatoo", rating: 5 }]
}]
};
function getMovies(arr) {
var movies = document.querySelector('#movies');
clearNode(movies);
getTopRatedFilms(user).forEach(function (movie) {
var elem = document.createElement("div");
elem.innerHTML = movie.name;
movies.appendChild(elem);
});
}
function clearMovies() {
var movies = document.querySelector('#movies');
clearNode(movies);
}
function clearNode(node) {
while (node.firstChild) {
node.removeChild(node.firstChild);
}
}
var getTopRatedFilms = function getTopRatedFilms(user) {
return user.videoLists.flatMap(function (videoList) {
return videoList.videos.filter(function (v) {
return v.rating === 5;
});
});
};
// https://gist.github.com/samgiles/762ee337dff48623e729
Array.prototype.flatMap = function (lambda) {
return [].concat.apply([], this.map(lambda));
};
</script>
<script id="jsbin-source-html" type="text/html"><!DOCTYPE html>
<html>
<head>
<script src="//fb.me/react-with-addons-0.13.3.js"><\/script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<h1>getTopRatedFilms()</h1>
<button onClick="getMovies()">getMovies</button>
<button onClick="clearMovies()">clearMovies</button>
<div id="movies"></div>
</body>
</html></script>
<script id="jsbin-source-javascript" type="text/javascript">/*jshint esnext: true */
// Async Programming at Netflix by Matthew Podwysocki at Web Rebels 2015 https://vimeo.com/128858567
let user = {
videoLists: [
{
name: "postapocalyptic",
videos: [
{ name: "Mad Max", rating: 5 },
{ name: "BlaBla", rating: 3 }
]
},
{
name: "thriller",
videos: [
{ name: "Nope", rating: 2 },
{ name: "The girl with the dragon tatoo", rating: 5 }
]
}
]
};
function getMovies(arr) {
let movies = document.querySelector('#movies');
clearNode(movies);
getTopRatedFilms(user)
.forEach(movie => {
let elem = document.createElement("div");
elem.innerHTML = movie.name;
movies.appendChild(elem);
});
}
function clearMovies() {
let movies = document.querySelector('#movies');
clearNode(movies);
}
function clearNode(node) {
while(node.firstChild) {
node.removeChild(node.firstChild);
}
}
let getTopRatedFilms = user =>
user.videoLists
.flatMap(videoList =>
videoList.videos
.filter(v => v.rating === 5)
);
// https://gist.github.com/samgiles/762ee337dff48623e729
Array.prototype.flatMap = function(lambda) {
return [].concat.apply([], this.map(lambda));
};</script></body>
</html>
/*jshint esnext: true */
// Async Programming at Netflix by Matthew Podwysocki at Web Rebels 2015 https://vimeo.com/128858567
"use strict";
var user = {
videoLists: [{
name: "postapocalyptic",
videos: [{ name: "Mad Max", rating: 5 }, { name: "BlaBla", rating: 3 }]
}, {
name: "thriller",
videos: [{ name: "Nope", rating: 2 }, { name: "The girl with the dragon tatoo", rating: 5 }]
}]
};
function getMovies(arr) {
var movies = document.querySelector('#movies');
clearNode(movies);
getTopRatedFilms(user).forEach(function (movie) {
var elem = document.createElement("div");
elem.innerHTML = movie.name;
movies.appendChild(elem);
});
}
function clearMovies() {
var movies = document.querySelector('#movies');
clearNode(movies);
}
function clearNode(node) {
while (node.firstChild) {
node.removeChild(node.firstChild);
}
}
var getTopRatedFilms = function getTopRatedFilms(user) {
return user.videoLists.flatMap(function (videoList) {
return videoList.videos.filter(function (v) {
return v.rating === 5;
});
});
};
// https://gist.github.com/samgiles/762ee337dff48623e729
Array.prototype.flatMap = function (lambda) {
return [].concat.apply([], this.map(lambda));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment