3 ms·
I never realized that functional programming was changing the way I think until I saw this problem and wondered how I'd solve it in ClojureScript: (let [num
by jdeisenberg 11y ago
I never realized that functional programming was changing the way I think until I saw this problem and wondered how I'd solve it in ClojureScript:
(let [numbers [14, 0, 5, 2, 0, 3, 0]
nonzero (filter (fn[x] (not= x 0)) numbers)]
(concat nonzero
(repeat (- (count numbers) (count nonzero)) 0)))
I imagine you could do something similar in Java 8 with the removeIf() method in java.util.Collection