SHARE
TWEET

Untitled

a guest May 21st, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. power_array = -> (power, array_size) do
  2.     1.upto(Float::INFINITY).lazy.map { |x| x**power }.first(array_size)
  3. end
  4.  
  5. puts power_array.(2 , 4)    #[1, 4, 9, 16]
  6. puts power_array.(2 , 10)   #[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
  7. puts power_array.(3, 5)     #[1, 8, 27, 64, 125]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top