0
Question statement: Construct a function that will receive two Strings of varying sizes and will return True or False if all characters (regardless of whether they are upper or lower case) are contained in both words.
Answer:
function verificacaoDeString (string1, string2) {
let estaContido = true;
for (let i = 0; i < string1.length; i++) {
let caractereString1 = string1.charAt(i).toLowerCase()
for(let j = 0; j < string2.length; j++){
let caractereString2 = string2.charAt(j).toLowerCase()
if(caractereString1 == caractereString2) {
estaContido = true
break
} else {
estaContido = false
}
}
if(!estaContido) {
return estaContido
}
}
return estaContido
}
My doubt is the question of the existence of this passage :
if(!estaContido) {
return estaContido
}
I apologize for the ignorance, but I also ask for your understanding that I am still a beginner in the developing world.
That sounds like an "Early-Return". That is, if the
for
internal fail (note, there are twofor
), then there is no reason to continue iterating. This probably can also be exchanged forif(!estaContido) { break }
, since in the end you already give areturn estaContido
. But, finally, both fulfill the same purpose: to stop the loop in the first error, instead of continuing.– Inkeliz