3 ms·
I wrote some Ruby in an interview. It was so terse, I had to explain to the interviewer (who favored Java) what the code did, and why it was linear instead of
by amorphid 11y ago
I wrote some Ruby in an interview. It was so terse, I had to explain to the interviewer (who favored Java) what the code did, and why it was linear instead of O(n^2). That was actually kind of fun.
- richardwhiuk 11y agoIf your code is sufficiently terse that it's not very understandable (such that the complexity isn't very understandable) surely that's a realistic red flag?
- gknoy 11y agoIf it's idiomatic Ruby (which some, like me, are not familiar with), I think it would not be a red flag if they could explain the details of what the syntactic sugar represents, and why its runtime is what it is.
- VLM 11y agoMy shipping boxes hold an even number of widgets, but I "have to" sell odd quantities and those need expensive mil spec styrofoam peanuts added to fill the hole. Here, have an array of possible shipment sizes. Given that array, if its shipping an odd number of widgets I wanna add an additional half widget shipping charge. newshipping = oldshipping.select{|i| i % 2 == 1 }.map{|i| i + 0.5 } My ridiculous fictional writing about shipping widgets is way more confusing than the idea that you can select and then chain right into a map. This probably looks really weird to a java guy but its not really all that mysterious. I wonder what that looks like in Java.
- fortpoint 11y agoIn Java it would look like this: List<Double> newshipping = oldshipping.stream().filter(i -> i % 2 == 1).map(i -> i + 0.5d).collect(Collectors.toList()); a bit more verbose but the essential chaining idea is there...
- sk5t 11y agoThe above, only if you want to discard (filter) orders with an even number of things. Also I'm not sure about the use of floating point here...
- kilotaras 11y agoRuby's select[1] is the same as java 8's filter[2]. [1] http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-select http://ruby-doc.org/core-2.2.3/Enumerable.html#method-i-sele... [2] https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#filter-java.util.function.Predicate- https://docs.oracle.com/javase/8/docs/api/java/util/stream/S...