Javascript 非常新,我在大约一个月的时间里已经尝试了这个问题大约 4 次,但我仍然无法解决它。
所以这里的问题是:构造一个函数交集,比较输入数组并返回一个包含在所有输入中找到的元素的新数组。奖励:使用减少!
格式为:
function intersection(arrays) {
// Your Code Goes Here
}
Run Code Online (Sandbox Code Playgroud)
测试用例:应该记录 [15, 5]
console.log('Extensions 3 Test: ' + intersection([5, 10, 15, 20], [15, 88, 1, 5, 7]/*, [1, 10, 15, 5, 20]*/));
Run Code Online (Sandbox Code Playgroud)
我目前的解决方案:适用于只有两个项目要比较的情况,但不适用于第三个项目,我可以这样做,以便我可以循环遍历并将获得的值与下一个数组进行比较,但我认为我不是在正确的道路上......另外,我没有使用 reduce 来实现它......而且我不确定我是否应该使用“参数”。任何帮助表示赞赏!非常感谢。
function intersection(arrays) {
array = [];
for (var i = 0; i < arguments.length; i++)
array.push(arguments[i]);
var result = [];
for(var i = 0; i < array.length - 1; i++) {
for(var j = 0; j < array[i].length; j++) { …Run Code Online (Sandbox Code Playgroud) 我以某种方式在编辑器的左侧和右侧添加了填充。有谁知道我怎样才能删除它?
我玩过视图-> 编辑器布局,但Single模式不起作用。切换到其他视图并返回也不会做任何事情。我也无法将窗口拖到下面显示的范围之外。
我当前的settings.json,这里没有任何影响。
{
"editor.tabSize": 2,
"editor.detectIndentation": false,
"window.zoomLevel": 1,
"editor.minimap.enabled": true,
"javascript.updateImportsOnFileMove.enabled": "always",
"[terraform]": {
"editor.formatOnSave": true
},
"breadcrumbs.enabled": true,
"[python]": {
"editor.insertSpaces": true,
"editor.tabSize": 4
},
"editor.renderWhitespace": "none"
}
Run Code Online (Sandbox Code Playgroud)