字段game_options
设置了一些参数
我需要查看请求的选项是否与game_options
game_options = ['ps2', 'pc']
request = ['ps2', 'pc', 'xbox']
此组合应返回false 但是这个:是的:
game_options = ['ps2', 'pc', 'xbox']
request = ['ps2', 'pc']
我用lodash完成了这个,但不确定它是否是正确的方法:
_ = require 'lodash'
hasAllRequestedOptions - (options, request) ->
return true if _.intersection(game_options, request).length is request.length
return false
答案 0 :(得分:0)
您可以使用difference功能来实现:
game_options = ['ps2', 'pc'];
request = ['ps2', 'pc', 'xbox'];
console.log(_.difference(game_options, request).length > 0);
game_options = ['ps2', 'pc', 'xbox'];
request = ['ps2', 'pc'];
console.log(_.difference(game_options, request).length > 0);
答案 1 :(得分:0)
var isPresented = _.intersection(game_options, request).length === request.length