Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Last active October 10, 2019 13:12
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 NyaGarcia/7f19fcd5211dc9b99fa1a957c9219f68 to your computer and use it in GitHub Desktop.
Save NyaGarcia/7f19fcd5211dc9b99fa1a957c9219f68 to your computer and use it in GitHub Desktop.
An example of duplicated code
function getJavascriptNews() {
const allNews = getNewsFromWeb();
const news = [];
for (let i = allNews.length - 1; i >= 0; i--){
if (allNews[i].type === "javascript") {
news.push(allNews[i]);
}
}
return news;
}
function getRustNews() {
const allNews = getNewsFromWeb();
const news = [];
for (let i = allNews.length - 1; i >= 0; i--){
if (allNews[i].type === "rust") {
news.push(allNews[i]);
}
}
return news;
}
function getGolangNews() {
const news = [];
const allNews = getNewsFromWeb();
for (let i = allNews.length - 1; i >= 0; i--) {
if (allNews[i].type === 'golang') {
news.push(allNews[i]);
}
}
return news;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment