I have my code where I capture the text, the idea is to count how many times the word BANANA is written in that text independently, whether I write it in order or out of order knowing that the word BANANA has 1 B, 3 A and 2 N.
For example, if I write NAABXXAN it will return 1 because the word BANANA is in the string once and out of order, and if I write NAANAAXNABABYNNBZ it will return 2 because the word BANANA is in the string twice and also out of order.
let vocalA=["A"];
function contarArray(str){
let contarVocal= 0;
for (let i of str.toUpperCase() ){
if (vocalA.includes(i)){
contarVocal++;
}
}
console.log("letras A");
//console.log("letA" + contarVocal);
return contarVocal
}
contarArray('BASCO')
Since I like to recycle I will take the function
numberOfCharacters
from this answerThen having the number of letters of each word, you only have to divide to know the number of words that can be formed.
for instance:
BANANA
NAANAAXNABABYNNBZ
Then we divide letter by letter
Then we are left with the smallest result, that is 2.
here the code
What I would do is place the word BANANA in an array: ArrBanana[] that I can iterate through. The input word would then also be placed in an InputArr[] array.
Now, the logic that I would do would be
Go through the ArrBanana letter by letter and remove each letter obtained from the ArrInput array. if you complete a cycle of the ArrBanana then you add an IntAux++ counter for example. If any of the letters in ArrBanana are not found, then you end the loop and return the counter.
Code example:
Cheers!