Skip to content

Instantly share code, notes, and snippets.

@prakhar1989
Last active August 29, 2015 14:24
Show Gist options
  • Save prakhar1989/9be9bf255d6c11a17d1f to your computer and use it in GitHub Desktop.
Save prakhar1989/9be9bf255d6c11a17d1f to your computer and use it in GitHub Desktop.
Get surnames of MS CS students at CU
// Before you run this code, add the id `ms` to the masters students HTML table
Array.from(
[].slice.call(document.querySelectorAll("table#ms tr"))
.map((tr) => tr.children[0].innerText.split(",")[0])
.reduce((acc, x) => {
acc.has(x) ? acc.set(x, acc.get(x) + 1) : acc.set(x, 1)
return acc;
}, new Map())
).sort(([valA, countA], [valB, countB]) => {
if (countA > countB) return -1;
else if (countA < countB) return 1;
else return valA > valB;
}).filter((_, i) => i < 10).forEach((x) => console.log(x))
@prakhar1989
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment