4 ms·
I think comparing it with other languages may make it easier to grasp. Sometimes it's good to test it in a language you are used to. The selector expression cou
by caioariede 10y ago
I think comparing it with other languages may make it easier to grasp. Sometimes it's good to test it in a language you are used to. The selector expression could be represented in Python like this:
a = lambda n: [n % x for x in [15, 3, 5]].index(0)
- 101km 10y agoYep, I started writing this out (first in js, but it doesn't map well, python list comprehensions do) but you beat me to it. :) Now great, you can get the weird syntax and unroll it if you squint. Why is it written like this? Isn't it wasteful to test against all three cases (15,3,5) instead of returning early? Probably has something to do with 'thinking in arrays' and how its a cheap comparison and that there's probably matrix multiplication or bit twiddling going on under there. That's the interesting bit to me. To get the feel for an array language. This fizzbuzz example is actually surprisingly interesting because of that.
- caioariede 10y agoIn fact, it's still not the same. In Python, the following expression will raise a ValueError. > a(2) In J, it will return the length of the array, as stated in the post.