为了账号安全,请及时绑定邮箱和手机立即绑定

codewars的一道题,搞不懂

codewars的一道题,搞不懂

梦里花落0921 2018-11-21 13:14:33
题目:Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.例子:Example 1:a1 = ["arp", "live", "strong"]a2 = ["lively", "alive", "harp", "sharp", "armstrong"]returns ["arp", "live", "strong"]Example 2:a1 = ["tarp", "mice", "bull"]a2 = ["lively", "alive", "harp", "sharp", "armstrong"]returns []要求:要求实现function inArray(array1,array2){}测试用例:a2 = ["lively", "alive", "harp", "sharp", "armstrong"] a1 = ["xyz", "live", "strong"] Test.assertSimilar(inArray(a1, a2), ["live", "strong"]) a1 = ["live", "strong", "arp"] Test.assertSimilar(inArray(a1, a2), ["arp", "live", "strong"]) a1 = ["tarp", "mice", "bull"] Test.assertSimilar(inArray(a1, a2), [])
查看完整描述

1 回答

?
红糖糍粑

TA贡献1815条经验 获得超6个赞

供参考:

function inArray(a1, a2){    return a1.filter(el_a1 => a2.find(el_a2 => el_a2.includes(el_a1))).sort();
}


查看完整回答
反对 回复 2018-12-10
  • 1 回答
  • 0 关注
  • 667 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信