Mini Linter


Hello all,

In the exercise Mini Linter, to get filter the unnecessary words, i used below as

let betterWords = storyWords.filter(word => {
return word !== ‘extremely’ && word !== ‘literally’ && word !== ‘actually’;

instead of the tutorial as :

let betterWords2 = storyWords.filter(word => {
return !unnecessaryWords.includes(word)

It works ok in the outcome. But I would like to know are they both ok? Or mine is less feasible in any way for any reason?



Hello :slight_smile:

That is an interesting question, I would like to start by admitting that you are right, both solutions are correct and will produce the same results. But if we would work together and I would get the first version of the script for a code review I would definitely leave a note that you should change this code.

I will try to explain why the second version is better, but let me start by saying that the reasons might be not simple to grasp, because they are related to everything that happens when you are done with writing the application and many students have problems with understanding these reasons as they might be too abstract. So bear with me here :slight_smile:

As we already established, both scripts are equal when it comes to the results. So now we have to ask ourselves some questions to establish which solution is better when it comes to the maintenance of this script. And this process is not trivial, you have to think about possible situations when something might break or when some trivial task becomes too complicated. Ok, few exemplary questions:

  1. what if I would like to add a next word that should be treated by the script as unnecessary?
  2. what if I would like to change the source of unnecessary words? maybe I would like to keep them in the external database so the users will have ability to add their own words?
  3. what if I would like to create a new function that would capitalize unnecessary words instead of deleting them?

Try to answer these questions and you will come to the conclusion that the second version of the script is much more easy to modify and maintain. For example, if we would like to change the source of words, from hard-coded strings to a list of words downloaded from the database or some sort of API in the first script you would have to change the logic (and the change would result in the code from the second version), because now you have a variable that holds the strings.


Thanks! I understand this now as the second one is “cleaner” and ''prettier" in a non-data-science way, and easier if another part is altered. :slight_smile:

It is well explained. Thanks!


You’re very welcome :panda_face:

I am truly happy that you found this helpful :slight_smile: