So, I have an array that looks like this.
["Enter Sandman", "One", "Nothing Else Matters", "Master of Puppets", "The Unforgiven", "The Day That Never Comes", "For Whom the Bell Tolls", "Fade to Black", "Sad But True", "Wherever I May Roam", "Turn the Page", "I Disappear", "Fuel", "Cyanide", "Seek & Destroy", "Whiskey In the Jar", "All Nightmare Long", "Battery", "Welcome Home (Sanitarium)", "The Unforgiven III", "The Unforgiven II", "King Nothing", "Ride the Lightning", "No Leaf Clover", "Until It Sleeps", "...And Justice for All", "Blackened", "The Memory Remains", "Hero of the Day", "The Four Horsemen", "Orion", "Creeping Death", "St. Anger", "Harvester of Sorrow", "Don't Tread on Me", "Broken, Beat & Scarred", "Disposable Heroes", "Fight Fire With Fire", "The End of the Line", "Trapped Under Ice", "Of Wolf and Man", "Whiplash", "My Apocalypse", "Suicide & Redemption", "The Shortest Straw", "Tuesday Gone"]
This array is created by this command.
artists = search_object.map{|x| x["trackName"]}.uniq.delete_if {|x| x == nil}
this works well, but I need to filter out a few more elements. The user enters a text box, and as I enter, I need to narrow down the results. For example, if the user types the line "Questions", I need to take out items that do not have this name or name. Thus, he unfolds before the "Nothing Else Matters". If the user enters the letter "a", then all the others in the array that do not have "a" will be deleted.
they will enter with the parameters [: text]
I did it and it worked, but maybe there is a cleaner way
query = params[:term] artists = search_object.map{|x| x["trackName"]}.uniq.delete_if {|x| x == nil} filtered = [] artists.each do |artist| filtered << artist if artist.include?(query) end