您好,欢迎来到北风网!

数组,对象的一个功能实现,for循环快绕晕了,有什么好的方法

加关注
15 1401
bennywo bennywo 2016-01-19 19:22:04 JavaScript

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"]

怎么实现guessGifts这个功能,codewars遇到的题目,自己写了一半天没写出来。
我想说明一下,wishlist.length和presents.length的个数未知,并且里面的键值对也是未知的,循环遍历的话要嵌套好几层,有没有其他更简单的办法?

请先登录