Hashes

Question:  Build me a method that takes a query shown below and returns those products from the array.

</pre>
PRODUCTS = [
{ name: "Thinkpad x210", price: 220 },
{ name: "Thinkpad x220", price: 250 },
{ name: "Thinkpad x250", price: 979 },
{ name: "Thinkpad x230", price: 300 },
{ name: "Thinkpad x230", price: 330 },
{ name: "Thinkpad x230", price: 350 },
{ name: "Thinkpad x240", price: 700 },
{ name: "Macbook Leopard", price: 300 },
{ name: "Macbook Air", price: 700 },
{ name: "Macbook Pro", price: 600 },
{ name: "Macbook", price: 1449 },
{ name: "Dell Latitude", price: 200 },
{ name: "Dell Latitude", price: 650 },
{ name: "Dell Inspiron", price: 300 },
{ name: "Dell Inspiron", price: 450 }
]

query = {
price_min: 240,
price_max: 280,
q: "thinkpad"
}

query2 = {
price_min: 300,
price_max: 450,
q: 'dell'
}

&nbsp;

def hash_getter(query)
PRODUCTS.select do |hsh|
((hsh[:name].start_with? query[:q].capitalize) && ((hsh[:price]) >= query[:price_min]) && (hsh[:price] <= query[:price_max] ))
end
end

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: