« get me outta code hell

Remove duplicates from explore-users - scratchrlol - Simple HTML-based Scratch client
summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorrie <towerofnix@gmail.com>2018-11-19 23:24:24 -0400
committerFlorrie <towerofnix@gmail.com>2018-11-19 23:24:24 -0400
commit5c8ce1db7004f8b44762a497438def8ea3c87fb5 (patch)
treee236dcd038578decc6ca18fe9e72295d2ae231f9
parent102254ee49a78464e67140b7cc4592105de8a547 (diff)
Remove duplicates from explore-users
-rwxr-xr-xindex.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/index.js b/index.js
index 24e8454..27552c9 100755
--- a/index.js
+++ b/index.js
@@ -317,8 +317,14 @@ const explore = {
     }
 
     const fetchResults = await Promise.all(['recent', 'trending', 'popular'].map(m => fetch(getUrl(m)).then(res => res.json())))
-    console.log(fetchResults)
     const projects = fetchResults.reduce((acc, arr) => acc.concat(arr), [])
+
+    // Dumb "remove duplicates" code incoming!
+    let authors = projects.map(project => project.author)
+    const seenUsernames = []
+    authors = authors.filter(
+      ({ username: un }) => seenUsernames.includes(un) ? false : (seenUsernames.push(un), true))
+
     const selected = shuffle(projects).slice(0, 15)
     return selected.map(project => project.author)
   }