Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ary = [1,2,3,4,6,7,5,4,3,3]
- array2 = ["hanging",'with','friends','is','super','fun']
- # TODO: Return the odd numbers from a list of integers.
- # Use #select.
- def odd_integers(array)
- array.select!{ |number| number.odd? }
- p array
- end
- # TODO: Return the first number from an Array that is less than a particular number - 'limit.'
- # Use #find.
- def first_under(array, limit)
- p array.find_all{ |number| number <= limit }
- end
- # TODO: Take an Array of Strings and return a new Array with an exclamation point appended to each String.
- # Use #map.
- def add_bang(array)
- array.map!{ |el| el +"!"}
- p array
- end
- def rotate_to_vowel(string)
- new_str = string.split('').rotate!
- p new_str
- until new_str[0] == (/[aeiou]/)
- new_str = string.split('').rotate!
- end
- end
- # TODO: Calculate the sum of an Array of numbers.
- # Use #reduce.
- def sum(array)
- p array.reduce(:*)
- end
- # TODO: Reorganize an Array of the elements into groups of 3, and then sort each group alphabetically.
- # Use #each_slice in combination with other enumerable methods.
- def sorted_triples(array)
- end
- # TODO: Returns an array of elements at indices 1, 3, 5, 7, etc.
- # Use #each_with_index.
- def odd_indexed_elements(array)
- end
- rotate_to_vowel("FRIENDS")
- add_bang(array2)
- first_under(ary,5)
- sum(ary)
- odd_integers(ary)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement