Skip to content

Questions about a specific Array exercise [Day 5] #614

Answered by Kashyap-Aayush
erthewise asked this question in Q&A
Discussion options

You must be logged in to vote

I am not proficient in JavaScript but I'll try my best
Regarding whats been asked by the question : The problem is asking you to separate the company that contain more than one alphabet 'o' in them e.g: G'o'o'gle which has 2 'o' in it while 'O'racle only has one 'o'

you could try .reduce method to iterate over elements in array and apply callback function to each element

const itCompanies = ['Facebook', 'Google', 'Microsoft', 'Apple', 'IBM', 'Oracle', 'Amazon'];

const companiesWithMoreThanOneO = itCompanies.reduce((acc, company) => {
if (company.split('o').length > 2) {
acc.push(company);
}
return acc;
}, []);

console.log(companiesWithMoreThanOneO);
I think this should give you correct ou…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@erthewise
Comment options

Answer selected by erthewise
Comment options

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
3 participants