Javascript algorithm help

Javascript algorithm help
0

#1

Hi I’d like help with this algorithm.

I have an array of verbs called ignoreVerb that contain certain verbs I don’t want to use.
I have a loop that goes over each verb and changes it.
If it is not one of the verbs in the ignoreVerb array, I want it to change it. If it is, I want it to ignore it.
var ignoreVerb = [‘was’, ‘is’, ‘do’, ‘did’, ‘does’];
the verbs array is too big to list but is called in a variable: var verbs


#2

What do you mean by change ? Anyway, here’s part of the solution :
considering that the array of verbs is called arrVerb

for (i=0,i<arrVerb.length,i++){
     if (ignoreVerb.indexOf(arrVerb[i])== -1){
          // code to change arrVerb[i];
     }
}

this will take all instance of arrVerb and look if it is in ignoreVerb, and ignore it if it is. It should work but I wrote it on the go, hopefully I didn’t do any mistakes.


#3

Thank you! @hadrienallemon. I’ll play around with that and get back to you.


#4

I’m wondering if the .some can work here. …