DEV Community

Discussion on: A Most Magic TicTacToe solution with React and TS

Collapse
 
rpresb profile image
Rodrigo De Presbiteris • Edited

Everything looks great, one thing that I think you don't need to do is spread the array for filtering. Filter doesn't mutate the array, so it's a bit of a waste of memory.

Collapse
 
kirkcodes profile image
Kirk Shillingford

Hey Rodrigo, do you mean the spread of the Combination object? IIRC, I spread into an array because the filter method isn't available on the combination directly.

But maybe there's a more efficient way to do that?

Collapse
 
rpresb profile image
Rodrigo De Presbiteris

You are right, this object doesn't generate a pure array.

it has the toArray function, but it does the same you did there.

 toArray() {
        return [...this];
    }
Enter fullscreen mode Exit fullscreen mode

I should have checked this before commenting

Thread Thread
 
kirkcodes profile image
Kirk Shillingford

No worries. I didn't even check to see if it implemented toArray(). That's probably the clearer way to express that intent. I'll use that instead. Thanks!