We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defselect_arr(arr)# select and return all odd numbers from the Array variable `arr`returnarr.select{|a|(a%2!=0)}enddefreject_arr(arr)# reject all elements which are divisible by 3returnarr.delete_if{|a|(a%3==0)}enddefdelete_arr(arr)# delete all negative elementsreturnarr.delete_if{|a|a<0}enddefkeep_arr(arr)# keep all non negative elements ( >= 0)returnarr.keep_if{|a|a>=0}end
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ruby Array - Selection
You are viewing a single comment's thread. Return to all comments →