Respuesta :
Using the knowledge in computational language in python it is possible to write a code that Given a string array that containsnelements, each composed of lowercase English letters, and q queries, eacl 1-r.
Writting the code:
function hasVowels(strArr, query) {
//variable to keep track of which index of the query we are on;
let queryCounter = 0;
//return array of solution
let returnQuery = [];
//loop through query array to determine vowel count
query.every((q) => {
//index1 and index 1 => get them from the query then make them into integers with + sign.
let index1 = +query[queryCounter][0];
let index2 = +query[queryCounter][2];
if (index1 < 1) {
return false;
}
if (index2 > strArr.length) {
return false;
}
if (index1 > index2) {
return false;
}
//increase query counter to get the next set of indexes.
queryCounter += 1;
let vowelCounter = 0;
//loop through the vowel array to determine the count. the loop will start at the index1 and stop at index 2 as per the requirements of the problem.
for (let start = index1 - 1; start <= index2 - 1; start += 1) {
let firstLetter = strArr[start][0];
let lastLetter = strArr[start].slice(-1);
if (isVowel(firstLetter) && isVowel(lastLetter)) {
vowelCounter += 1;
}
}
returnQuery.push(vowelCounter);
vowelCounter = 0;
return true;
});
if (returnQuery.length === 0) {
return [0];
}
return returnQuery;
}
function isVowel(c) {
return ["a", "e", "i", "o", "u"].indexOf(c.toLowerCase()) !== -1;
}
See more about python at brainly.com/question/18502436
#SPJ1
