サンタの工房で、エルフたちは魔法の手袋の山を、めちゃくちゃに積み上げられた状態で見つけました。 それぞれの手袋は次の2つの値で表されています。
hand: 左手袋(L)か右手袋(R)かを示すcolor: 手袋の色(文字列)あなたの仕事は、彼らが手袋をペアにするのを手伝うことです。 有効なペアは、同じ色の左手袋と右手袋1つずつです。
見つかったすべてのペアの色を配列で返さなければなりません。 同じ色のペアが複数ある場合もあることに注意してください。 順番は、ペアにできた順になります。
const gloves = [
{ hand: 'L', color: 'red' },
{ hand: 'R', color: 'red' },
{ hand: 'R', color: 'green' },
{ hand: 'L', color: 'blue' },
{ hand: 'L', color: 'green' }
]
matchGloves(gloves)
// ["red", "green"]
const gloves2 = [
{ hand: 'L', color: 'gold' },
{ hand: 'R', color: 'gold' },
{ hand: 'L', color: 'gold' },
{ hand: 'L', color: 'gold' },
{ hand: 'R', color: 'gold' }
]
matchGloves(gloves2)
// ["gold", "gold"]
const gloves3 = [
{ hand: 'L', color: 'red' },
{ hand: 'R', color: 'green' },
{ hand: 'L', color: 'blue' }
]
matchGloves(gloves3)
// []
const gloves4 = [
{ hand: 'L', color: 'green' },
{ hand: 'L', color: 'red' },
{ hand: 'R', color: 'red' },
{ hand: 'R', color: 'green' }
]
matchGloves(gloves4)
// ['red', 'green']

