Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. ary = [1,2,3,4,6,7,5,4,3,3]
  2.  
  3. array2 = ["hanging",'with','friends','is','super','fun']
  4.  
  5. # TODO: Return the odd numbers from a list of integers.
  6. # Use #select.
  7. def odd_integers(array)
  8. array.select!{ |number| number.odd? }
  9. p array
  10. end
  11.  
  12.  
  13. # TODO: Return the first number from an Array that is less than a particular number - 'limit.'
  14. # Use #find.
  15. def first_under(array, limit)
  16. p array.find_all{ |number| number <= limit }
  17.  
  18. end
  19.  
  20. # TODO: Take an Array of Strings and return a new Array with an exclamation point appended to each String.
  21. # Use #map.
  22. def add_bang(array)
  23. array.map!{ |el| el +"!"}
  24. p array
  25. end
  26.  
  27. def rotate_to_vowel(string)
  28. new_str = string.split('').rotate!
  29. p new_str
  30. until new_str[0] == (/[aeiou]/)
  31. new_str = string.split('').rotate!
  32. end
  33. end
  34.  
  35. # TODO: Calculate the sum of an Array of numbers.
  36. # Use #reduce.
  37. def sum(array)
  38. p array.reduce(:*)
  39. end
  40.  
  41. # TODO: Reorganize an Array of the elements into groups of 3, and then sort each group alphabetically.
  42. # Use #each_slice in combination with other enumerable methods.
  43. def sorted_triples(array)
  44. end
  45.  
  46. # TODO: Returns an array of elements at indices 1, 3, 5, 7, etc.
  47. # Use #each_with_index.
  48. def odd_indexed_elements(array)
  49. end
  50.  
  51. rotate_to_vowel("FRIENDS")
  52.  
  53.  
  54. add_bang(array2)
  55. first_under(ary,5)
  56. sum(ary)
  57. odd_integers(ary)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement