5 kyu

Guess The Gifts!

2,307 of 3,741BattleRattle

Description:

It's Christmas! You had to wait the whole year for this moment. You can already see all the presents under the Christmas tree. But you have to wait for the next morning in order to unwrap them. You really want to know, what's inside those boxes. But as a clever child, you can do your assumptions already.

You know, you were a good child this year. So you may assume, that you'll only get things from your wishlist. You see those presents, you can lift them and you can shake them a bit. Now you can make you assumptions about what you'll get.

Your Task

You will be given a wishlist (array), containing all possible items. Each item is in the format: {name: "toy car", size: "medium", clatters: "a bit", weight: "medium"} (Ruby version has an analog hash structure, see example below)

You also get a list of presents (array), you see under the christmas tree, which have the following format each: {size: "small", clatters: "no", weight: "light"}

Your task is to return the names of all wishlisted presents that you might have gotten.

Rules

  • Possible values for size: "small", "medium", "large"
  • Possible values for clatters: "no", "a bit", "yes"
  • Possible values for weight: "light", "medium", "heavy"
  • Don't add any item more than once to the result
  • The order of names in the output doesn't matter
  • It's possible, that multiple items from your wish list have the same attribute values. If they match the attributes of one of the presents, add all of them.

Example

var wishlist = [
    {name: "Mini Puzzle", size: "small", clatters: "yes", weight: "light"},
    {name: "Toy Car", size: "medium", clatters: "a bit", weight: "medium"},
    {name: "Card Game", size: "small", clatters: "no", weight: "light"}
];

var presents = [
    {size: "medium", clatters: "a bit", weight: "medium"},
    {size: "small", clatters: "yes", weight: "light"}
];

guessGifts(wishlist, presents); // must return ["Toy Car", "Mini Puzzle"]
wishlist = [
    {name: "Mini Puzzle", size: "small", clatters: "yes", weight: "light"},
    {name: "Toy Car", size: "medium", clatters: "a bit", weight: "medium"},
    {name: "Card Game", size: "small", clatters: "no", weight: "light"}
]

presents = [
    {size: "medium", clatters: "a bit", weight: "medium"},
    {size: "small", clatters: "yes", weight: "light"}
]

guessGifts(wishlist, presents); # must return ["Toy Car", "Mini Puzzle"]
wishlist = [
    {:name => "mini puzzle", :size => "small", :clatters => "yes", :weight => "light"},
    {:name => "toy car", :size => "medium", :clatters => "a bit", :weight => "medium"},
    {:name => "card game", :size => "small", :clatters => "no", :weight => "light"}
]

presents = [
    {:size => "medium", :clatters => "a bit", :weight => "medium"},
    {:size => "small", :clatters => "yes", :weight => "light"}
]

guess_gifts(wishlist, presents) # must return ['toy car', 'mini puzzle']
wishlist = [{'name': "mini puzzle", 'size': "small", 'clatters': "yes", 'weight': "light"},
            {'name': "toy car", 'size': "medium", 'clatters': "a bit", 'weight': "medium"},
            {'name': "card game", 'size': "small", 'clatters': "no", 'weight': "light"}]
presents = [{'size': "medium", 'clatters': "a bit", 'weight': "medium"},
            {'size': "small", 'clatters': "yes", 'weight': "light"}]

guess_gifts(wishlist, presents) # => must return ["Toy Car", "Mini Puzzle"]
Algorithms

Similar Kata:

Stats:

CreatedDec 16, 2013
PublishedDec 16, 2013
Warriors Trained7490
Total Skips1528
Total Code Submissions15990
Total Times Completed3741
JavaScript Completions2307
CoffeeScript Completions88
Ruby Completions879
Python Completions471
Total Stars126
% of votes with a positive feedback rating94% of 373
Total "Very Satisfied" Votes330
Total "Somewhat Satisfied" Votes40
Total "Not Satisfied" Votes3
Total Rank Assessments9
Average Assessed Rank
5 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
6 kyu
Ad
Contributors
  • BattleRattle Avatar
  • jhoffner Avatar
  • FArekkusu Avatar
  • albertogcmr Avatar
Ad