Filtering in Haskell, JavaScript, and Ruby

Haskell

let numList = [1..4]
filter even numList

=> returns [2,4]

Javascript

var numList = [1,2,3,4]
numList.filter(function(elem){
  return elem % 2 == 0
})

=> returns [2,4]

Ruby

num_list = Array(1..4)
num_list.select{|num| num.even?}

=>returns [2,4]

Leave a Reply