Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React by Example Refining the App Filter Bug

"Filter bug" chapter in "React by example"

Can't the bug be solved by using indexOf like this?

handleConfirmation={() => props.toggleConfirmationAt(props.guests.indexOf(guest))}

It'll then find the index the current guest (in map) has in the guest's array in state and use that index to toggle the confirmation?

1 Answer

Hi Thomas,

Your code will still execute but in reality, you'd probably be iterating over a list of entries queried from a database, at this point, it is expedient you use the id property as it has more integrity than using index.

Moreover, using indexOf will make your iterate over the array in (n*2) times, which implies that, the execution time will be high and its a lot of work considering system memory, imagine you'r dealing with over 10k element array.

I hope this helps.

Cheers

Thank you, Tosin, that makes sense :)

You welcome.