我有两个代表棒球运动员的对象,我想看看他们是否曾经在同一个队打过球,他们所效力的每支球队都有一个球队对象,属性是名字和他们在那支球队效力的年数,我想比较这两个对象,看看是否有重叠。
{
"_id": "/players/h/hunteto01.shtml",
"url": "/players/h/hunteto01.shtml",
"name": "Torii Hunter",
"image": "https://www.baseball-reference.com/req/202108020/images/headshots/7/79f9873b_br.jpg",
"teams": [{
"name": "MIN",
"years": [1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2015]
}, {
"name": "LAA",
"years": [2008, 2009, 2010, 2011, 2012]
}, {
"name": "DET",
"years": [2013, 2014]
}],
"searchName": "torii hunter"
}
{
"_id": "/players/m/mauerjo01.shtml",
"url": "/players/m/mauerjo01.shtml",
"name": "Joe Mauer",
"image": "https://www.baseball-reference.com/req/202108020/images/headshots/4/43c69595_mlbam.jpg",
"teams": [{
"name": "MIN",
"years": [2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018]
}],
"searchName": "joe mauer"
}
重叠发生在MIN 2004, 2005, 2006, 2007, 2015
,我只需要返回一个布尔值,我实际上不需要值或任何东西,我怎么在javascript中完成这个。
1条答案
按热度按时间nlejzf6q1#
你能做这样的事吗?
或者,如果你喜欢一个可能更干净的方法,你也可以这样做: