DEV Community

Discussion on: [Challenge] šŸ FizzBuzz without if/else

Collapse
 
coreyja profile image
Corey Alexander

I'm pretty sure the first pair of square brackets creates an array, and the second one indexes into that array. So I think they are array indexing into the first array with either 0 or 1 to pick the empty string or "Fizz" depending on the offsetIndex!

Hope that helps!

Thread Thread
 
nombrekeff profile image
Keff

yup, it defines the array first const array = ["", "Fizz"] and then access the index array[!(offsetIndex % 3) + 0]. The expression will resolve either to true+0 -> 1 or false+0 -> 0

Thread Thread
 
ogrotten profile image
ogrotten

holy shit. that's cool.

I THOUGHT it might have been something like that, but I was thinking about it wrongly . . . I wasn't thinking of it as the array followed by the index, I was thinking of it as a variable. So ["an", "array"] was the name of the array, and then it had it's own index. Not very practical.

But the actual use is quite cool and makes plenty sense.

Thanks!