Comments (3)
非常感谢。这题目的关键在于函数的参数被自动保存在arguments数组中,因此参数的数量可变就不成问题了。
如果这个点不知道,什么算法都是白搭。
from freecodecamp.cn.
不好意思,这个怪我们的翻译不到位,题目原文为:
You will be provided with an initial array (the first argument in the destroyer function), followed by one or more arguments. Remove all elements from the initial array that are of the same value as these arguments.
也就是说这个方法传入的参数个数是不固定的,第一个参数是一个待操作的数组,之后的每个参数是需要你在这个数组中删除的与之相等的值。这么说很绕,举个例子:
destroyer([1, 2, 3, 1, 2, 3], 2, 3)
的意思就是删除[1, 2, 3, 1, 2, 3]里面的所有2和3。
from freecodecamp.cn.
@Sagitarioo 函数的形参arr并不等于我们实际传输的参数,只有arguments才等于实参。
此处的形参arr仅仅是实参的第一个参数,即数组。
上图来自javascript面向对象精要2.3节,希望对你有帮助。
课程中有提示文档:arguments,
所以很显然此题需要用到arguments来获取到实参,并把arguments对象转化为数组。
var args = Array.from(arguments); // es6 写法
var args = Array.prototype.slice.call(arguments); // es3写法
var args = [].slice.call(arguments); // es3写法简写
如果还是不理解请参考MDN:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/slice#Array-like
如果想了解更多解法可以参考Wiki:https://github.com/huluoyang/freecodecamp.cn/wiki/seek-and-destroy
from freecodecamp.cn.
Related Issues (20)
- Why I can't pass the test?
- no need to use break HOT 2
- 输入参数检验结果是正确的,但是就是通不过运行
- "25 or More" is wrong ,but I can't fix it. HOT 1
- "9 or Under" is wrong ,but I can't fix it. HOT 1
- why i can't pass Create a Bootstrap Row, pls help?
- Truncate a string 有点问题
- Add your JavaScript Slot Machine Slots 文字错误
- Build a Tribute Page |观看不了右边视频,是否有其他视频源 HOT 1
- 在style标签的最后两段代码,按照要求添加的Id选择器,代码无法通过,并无明显错误,不知道什么原因?
- The Code I write wrong deliberately can run and work as well. HOT 1
- 代码输出正确,却不能通过测试 I'm a little tea pot HOT 1
- 点击校验
- input中type属性checkbook无法识别
- 这个为什么不能过去呢
- Chinese interface:It allows data structures to be any combination of strings, numbers, Booleans, strings, and objects.Did you write "strings" again?
- 这个是BUG吗 HOT 1
- 这样为什么会显示错误
- 为什么过不去?例题和实际无联系。 HOT 1
- 哪里有“我已经完成了这个挑战按钮”啊
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freecodecamp.cn.