Skip to content
Advertisement

Dynamically Find Values from a Variable

JavaScript

Please can you help me try figure out how to dynamically check if a sentence includes any values that another variable includes and count that value.

JavaScript

You can see that I have had to create a singular variable for each of the words that are part of the string for variable – overUsedWords in order to be able to count them in the loop and if else statement. There must be a way to beaten this up so I don’t have to do it with

JavaScript

Let me know what you think. I do apologise if this is super simple stuff. I’m just learning

Advertisement

Answer

JavaScript

In this way you are simply filtering the list of the word obtained by the splitting of the story for each of the word inside your overusedWord list and returning the count of them. In this way if you want to add further words you just have to add them into your ‘overusedWord’ array and it will continue to work.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement