Skip to content

Instantly share code, notes, and snippets.

@swalberg
Last active December 1, 2022 00:13
Show Gist options
  • Save swalberg/b758263224d8654704734423c880d401 to your computer and use it in GitHub Desktop.
Save swalberg/b758263224d8654704734423c880d401 to your computer and use it in GitHub Desktop.
def Organizer(🎁)
🎁.select{|🧽|🧽.is_a?(String)&&🧽.size>5&&🧽!='tomatoes' }
end
# Modify the solution above. Emojis are free.
# Code below will check correctness.
example_collection = [
'apples',
33,
nil,
'hat',
'tomatoes',
'toothbrush',
'laptop'
]
collection_two = [
'my best friend gary',
Array,
'hairbrush',
'drawers',
99
]
collection_three = [
'tomatillos',
'tin',
'table',
'mother-in-law'
]
raise unless Organizer(example_collection) == ["apples", "toothbrush", "laptop"]
raise unless Organizer(collection_two) == ["my best friend gary", "hairbrush", "drawers"]
raise unless Organizer(collection_three) == ["tomatillos", "mother-in-law"]
puts 'It works!'
@swalberg
Copy link
Author

swalberg commented Dec 1, 2022

l7 is bugging me, there has to be a way to avoid checking for the string first...

@swalberg
Copy link
Author

swalberg commented Dec 1, 2022

Really wasn't clear that we need all the ceremony so it all goes into the Organizer method. But still looking at that String -> >, if I use a safe nav operator I get nils to deal with which doesn't seem any shorter.

@swalberg
Copy link
Author

swalberg commented Dec 1, 2022

Wasn't sure if spaces counted, but let's strip those out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment