Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript React by Example Building the Application Removing Names From the List

Sam Gord
Sam Gord
14,060 Points

check my solution and tell if theres any disadvantage using the method i used,

for creating a function to delete Guest what i did was to filter the guests array like this -->

  deletePlayer = indexToDelete => {
      players: this.state.players.filter((player, index) => {
        if (indexToDelete !== index) {
          return player;
        return null;


instead of using two slices like what the teacher did, can you detect any problems with my code? thanks so much

2 Answers

Steven Parker
Steven Parker
217,557 Points

Have you tested this thoroughly? the MDN page recommends that arrow function expressions "... are best suited for non-method functions," probably because of the fact they don't establish "this" like conventional functions do. So your references to "this" will bind to whatever it represents in the outer context.

If you were using hooks instead of classes you would not have to worry about 'this' and it would be fine. Also you can remove the if statement

      players: this.state.players.filter((player, index) => indexToDelete !== index)