JavaScript
https://leetcode.com/problems/determine-if-string-halves-are-alike/
Ushbu algoritmni yechishga harakat qilib ko'ring. Yechimlaringizni @jsfamily_bot ga yuborishingiz mumkin. Eng optimal yechim kanalda e'lon qilinadi.
JavaScript
https://leetcode.com/problems/determine-if-string-halves-are-alike/
Funksiya ixtiyoriy uzunligi 2 ga bo'linadigan so'z qabul qiladi. Ushbu so'z teng ikkiga bo'linadi. Masalan book bo'lsa bo bilan ok shaklida. Keyin ushbu bo'lingan so'zlardan unli harflar sanaladi. Agarda ikkalasida ham unli harflar soni teng bo'lsa funksiya true qaytarsin aks holda false qaytarsin.
Harflar katta kichik bo'lishi mumkin. Uni ahamiyati yo'q
Harflar katta kichik bo'lishi mumkin. Uni ahamiyati yo'q
JavaScript
https://leetcode.com/problems/determine-if-string-halves-are-alike/
function halvesAreAlike(str){
let volwes=['a','i','e','o','u','A','I','E','O','U']
let a=str.slice(0,str.length/2)
let b=str.slice(str.length/2)
let count1=0, count2=0
for(let aelement of a){
if(volwes.includes(aelement)){
count1++
}
}
for(let belement of b){
if(volwes.includes(belement)){
count2++
}
}
return count1===count2
}
console.log(halvesAreAlike('AbCdEfGh'))
let volwes=['a','i','e','o','u','A','I','E','O','U']
let a=str.slice(0,str.length/2)
let b=str.slice(str.length/2)
let count1=0, count2=0
for(let aelement of a){
if(volwes.includes(aelement)){
count1++
}
}
for(let belement of b){
if(volwes.includes(belement)){
count2++
}
}
return count1===count2
}
console.log(halvesAreAlike('AbCdEfGh'))
Variantlar
Anonymous Quiz
46%
11,13,2,14
24%
11,13,2
23%
SyntaxError:Illegal break statement
8%
undefined