Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Day 5 Level 1 Q14 #772

Unanswered
Harufuu asked this question in Q&A
Discussion options

let itCompanies = [
 "Facebook",
 "Google",
 "Microsoft",
 "Apple",
 "IBM",
 "Oracle",
 "Amazon"
 ]
// Filter out companies which have more than one 'o' without the filter method

I solve it with the For loop, something like this

let filtered_array = [];
for(i = 0; i < itCompanies.length; i++) {
 let thing = itCompanies[i];
 if(thing.indexOf("o") !== thing.lastIndexOf("o")){
 filtered_array.push(thing);
 }
}
console.log(filtered_array) // [ 'Facebook', 'Google', 'Microsoft' ] 

The problem is that the loop stuff would first appear in the course on Day 6, while this is a question in the Day 5 exercise. So, I wonder if there is a solution that does not involve either the filter method or the loop.

You must be logged in to vote

Replies: 2 comments

Comment options

So all we just have to do is when you a question and it so confusing just leave it blank and move on with the next one then come back to that question again when you have more confidence.
...
On Sat, 3 Jun 2023, 19:06 Harufuu, ***@***.***> wrote: let itCompanies = [ "Facebook", "Google", "Microsoft", "Apple", "IBM", "Oracle", "Amazon" ]// Filter out companies which have more than one 'o' without the filter method I solve it with the For loop, something like this let filtered_array = [];for(i = 0; i < itCompanies.length; i++) { let thing = itCompanies[i]; if(thing.indexOf("o") !== thing.lastIndexOf("o")){ filtered_array.push(thing); }} console.log(filtered_array) // [ 'Facebook', 'Google', 'Microsoft' ] The problem is that the loop stuff would first appear in the course on Day 6, while this is a question in the Day 5 exercise. So, I wonder if there is a solution that does not involve either the filter method or the loop. — Reply to this email directly, view it on GitHub <#772>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/A7NPDWLOD5WWUPVZUFEEU33XJN4IZANCNFSM6AAAAAAYZNQ5DI> . You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
You must be logged in to vote
0 replies
Comment options

@Harufuu Here, it may help you.

let itCompanies = ['facebook', 'google', 'microsoft', .....]
var newArray = []
itCompanies.map((v,i)=>{
if(v.includes('o')){
newArray.push(v);
}
})
console.log(newArray); // [items with o will be added here.]
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /