Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1096697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:19:10+00:00 2026-05-17T00:19:10+00:00

Ok so I have an array that looks like this. [Enter Sandman, One, Nothing

  • 0

Ok 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's Gone"]

This array is generated 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 some more elements. The user will type in the textfield and as they type i need to narrow the results. So for example if the user types the string “Matters” i need to take out the elements that dont have that in the name or like the name. So it narraws down to “Nothing Else Matters”. If the user enters the letter “a” then all the others in the array that dont have an “a” get deleted.

they will come in with the params[:text]

I did this 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:19:10+00:00Added an answer on May 17, 2026 at 12:19 am

    the fast ruby variant is:

    albums = ["hello kitty", "bad day", "all is good", "day is okay"]
    
    def filter_word_in(word,array)
        array.delete_if { |data| !data.match(word) }
        return array
    end
    
    result1 = filter_word_in("y", albums)
    puts result1.inspect # => ["hello kitty", "bad day", "day is okay"]
    
    result2 = filter_word_in("ay", result1)
    puts result2.inspect # => ["bad day", "day is okay"]
    
    result3 = filter_word_in("day", result2)
    puts result3.inspect # => ["bad day", "day is okay"]
    
    result4 = filter_word_in("day i",result3)
    puts result4.inspect # => ["day is okay"]
    

    How you can see in this code: we just save our result in variables.
    So, where we can store our data in rails?
    You can use user_model for this, or you can just store this data in memory.

    Create something like this:

    class UserSongMemory
        attr_accessor :memory
    
        def initialize
            @memory = []
        end
    
        def push(id, data)
            @memory << {id => data}
        end
    
        def pop(id)
            @memory.delete_if {|obj| obj.id == id}
        end
    end
    
    user_memory = UserSongMemory.new
    user_memory.add(@user.id, params[:inputed_string])
    
    # after our calculations
    user.pop(@user.id)
    

    I prefer to store state memory in Class, but don’t forget to clean this class-data

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one array that contains some settings that looks like basically like this:
I have an array that looks like this: var y = [1, 2, 3];
I have a array that looks like this: $sites = array('Twitter' => 'http://twitter.com/home?status=$status', 'Digg'
I have an array that looks like this. [{EntryId=>2, Field1=>National Life Group,DateCreated=>2010-07-30 11:00:14, CreatedBy=>tristanoneil},
I have a multi-dimensional array right now that looks like this: function art_appreciation_feeds() {
I have an xml file that looks like this <step> <id>3</id> <backid>1</backid> <question>Are you
I have an array that looks just like that: array(3) { [fk_article_id]=> string(1) 4
I have byte array as input. I would like to convert that array to
I have a form element that I'm setting as required: $this->addElement('text', 'email', array( 'label'
I have a structure that contains an arrays of another structure, it looks something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.