JSFiddle - React, Tailwind, and code Playground
JavaScript
var yourString = "No depending be convinced in unfeeling he. "+
"Excellence she unaffected and too sentiments her. "+
"Rooms he doors there ye aware in by shall. "+
"Education remainder in so cordially. "+
"His remainder and own dejection Excellence daughters sportsmen. "+
"Is easy took he shed to kind. ";
var requiredWords = {
Rooms: 1,
Excellence: 2,
Education: 1,
House: 1,
};
var success = true;
for(var word in requiredWords){
var requiredAmount = requiredWords[word];
//create and check against regex
var regex = new RegExp(word, 'g');
var count = (yourString.match(regex) || []).length;
//if it doesn't occur often enough, the string is not ok
var isOK = count >= requiredAmount;
console.log(word + '('+count+'): '+ isOK);
if(!isOK){
success = false;
}
}
console.log(success);