arrays - prime number test in Ruby -


i have array a = [1,2,3,4,5]. want test of numbers prime , wanted produce output {1=>false, 2=>true, 3=>true, 4=>false, 5=>true}.

any 1 liner appreciated.

the below work you,using prime#prime?:

require 'prime'  = [1,2,3,4,5] hash[a.zip(a.map(&prime.method(:prime?)))] # => {1=>false, 2=>true, 3=>true, 4=>false, 5=>true} 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -