News for hackers. Stuff that matters.
Re:How to Pass a Programming Interview by VLM on Tuesday March 08, 2016 @04:06PM (#11248629)
My 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.

Re:How to Pass a Programming Interview by fortpoint on Tuesday March 08, 2016 @04:37PM (#11248898)
In 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...

Re:How to Pass a Programming Interview by sk5t on Tuesday March 08, 2016 @08:02PM (#11250097)
The 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...

Re:How to Pass a Programming Interview by kilotaras on Wednesday March 09, 2016 @05:41AM (#11252122)