I'm trying to remove all of the items with more than one 'o' from the itCompanies array and then print the array to console. I'm not sure why, but when I'm splitting each item in the array to letters to check if there are more than one 'o', Google and Apple both get skipped.
const itCompanies = ['Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'];
for (let i = 0; i < itCompanies.length; i++){
let s = itCompanies[i].split('');
let count = 0;
for (let j = 0; j < s.length; j++){
if (s[j] == 'o' ){
count++;
}
}
if (count >= 2){
itCompanies.splice(i, 1);
}
}
console.log(itCompanies);
Output
Array(5)
0: "Google"
1: "Apple"
2: "IBM"
3: "Oracle"
4: "Amazon"
Wanted Output
Array(5)
0: "Apple"
1: "IBM"
2: "Oracle"
3: "Amazon"