Skip to content

Instantly share code, notes, and snippets.

@russelllim22
Created December 3, 2021 21:18
Show Gist options
  • Save russelllim22/9ae356f8c0f7b6ef330dbf2275d2414d to your computer and use it in GitHub Desktop.
Save russelllim22/9ae356f8c0f7b6ef330dbf2275d2414d to your computer and use it in GitHub Desktop.
const totalBabies = letterCounts.reduce((a, b) => a + b.count, 0);
const smallCounts = {letter: "other", count: 0, otherLetters: ""}
for(let i = 25; i>=0; i--){
if(letterCounts[i].count < 0.015*totalBabies){
smallCounts.otherLetters += `${letterCounts[i].letter},`;
smallCounts.count += letterCounts[i].count;
letterNames["other"] = letterNames["other"].concat(letterNames[letterCounts[i].letter])
letterCounts.splice(i,1)
}
}
letterCounts.sort((a,b)=> d3.descending(a.count, b.count))
letterCounts.push(smallCounts);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment