Hello,
I’m writing something to change verbs in text. I’m using the compromise library. What I want to do is prevent the verb in the foreach loop from changing if it is in the ignoreVerbs array.
var verbs = doc.verbs().out('array');
var ignoreVerb = ['was', 'is', 'do', 'did', 'does'];
verbs.forEach(function(verb) {
if (Math.random() < 0.3) {
var re = new RegExp('\\b'.concat(verb, '\\b'));
var chosen_style = verb_style[Math.floor(Math.random()*3)];
modified_text = modified_text.replace(re, chosen_style.concat('$&</span>'));
}
});
No, .some() only gives you a boolean value, to tell you if at least one of the array items matched the criteria.
It’s a more complex way of doing Array.indexOf()