function fetchPlaylistsContainingVideo(videoId) {
	const baseURL = 'https://gdata.youtube.com/feeds/api/playlists/snippets';
	const url = baseURL + '?v=2&alt=jsonc&max-results=50&q=' + id;
	return fetch(url);
}

function fetchPlaylist(id) {
	const baseURL = 'https://gdata.youtube.com/feeds/api/playlists';
	const url = baseURL + '/' + id + '?v=2&alt=jsonc';
	return fetch(url);
}

function mergePlaylists(playlists) {
	let videos = {};
	let videoIDs = [];
	let merged = [];
	let promiseArr = playlists.data.items.map(i => {
		return fetchPlaylist(i.id).then(resp => resp.json());
	})
	return Promise.all(promiseArr).then((playlists) => {
		playlists.forEach((playlist) => {
			playlist.data.items.forEach((item) => {
				if (item.video.id in videos) {
					videos[item.video.id].count++;
				} else {
					videos[item.video.id] = item;
					videos[item.video.id].count = 1;
					videoIDs.push(item.video.id);
				}
			});
		});
		merged = videoIDs.map(id => videos[id]);
		return merged;
	});
}

function sortMergedPlaylist(playlist) {
	let compareFunction = (a, b) => a.count - b.count;
	return playlist.sort(compareFunction);
}

function fetchRelated(videoId) {
	return fetchPlaylistsContainingVideo(videoId)
		.then(resp => resp.json())
		.then(mergePlaylists)
		.then(sortMergedPlaylist);
}

export default fetchRelated;

@@ -384,21 +384,24 @@
 unction 
-merge
+fetchAll
 Playlist
@@ -420,66 +420,12 @@
  %7B%0A%09
-let videos = %7B%7D;%0A%09let videoIDs = %5B%5D;%0A%09let merged = %5B%5D;%0A%09le
+cons
 t pr
@@ -526,16 +526,17 @@
 ());%0A%09%7D)
+;
 %0A%09return
@@ -563,32 +563,106 @@
 Arr)
-.then((playlists) =%3E %7B%0A%09
+;%0A%7D%0A%0Afunction mergePlaylists(playlists) %7B%0A%09let videos = %7B%7D;%0A%09let videoIDs = %5B%5D;%0A%09let merged = %5B%5D;%0A
 %09pla
@@ -692,17 +692,16 @@
 t) =%3E %7B%0A
-%09
 %09%09playli
@@ -737,17 +737,16 @@
 =%3E %7B%0A%09%09%09
-%09
 if (item
@@ -768,17 +768,16 @@
 deos) %7B%0A
-%09
 %09%09%09%09vide
@@ -803,17 +803,16 @@
 ount++;%0A
-%09
 %09%09%09%7D els
@@ -815,25 +815,24 @@
  else %7B%0A%09%09%09%09
-%09
 videos%5Bitem.
@@ -849,17 +849,16 @@
 = item;%0A
-%09
 %09%09%09%09vide
@@ -886,17 +886,16 @@
 nt = 1;%0A
-%09
 %09%09%09%09vide
@@ -927,25 +927,21 @@
 %0A%09%09%09
-%09
 %7D%0A
-%09
 %09%09%7D);%0A
-%09
 %09%7D);%0A
-%09
 %09mer
@@ -978,17 +978,16 @@
 s%5Bid%5D);%0A
-%09
 %09return 
@@ -994,21 +994,16 @@
 merged;%0A
-%09%7D);%0A
 %7D%0A%0Afunct
@@ -1038,18 +1038,20 @@
 ist) %7B%0A%09
-le
+cons
 t compar
@@ -1243,16 +1243,44 @@
 json())%0A
+%09  .then(fetchAllPlaylists)%0A
 %09%09.then(

make more readable :)