GithubHelp home page GithubHelp logo

Comments (3)

cxmSevenlaps avatar cxmSevenlaps commented on May 1, 2024 1

非常感谢。这题目的关键在于函数的参数被自动保存在arguments数组中,因此参数的数量可变就不成问题了。
如果这个点不知道,什么算法都是白搭。

from freecodecamp.cn.

discountry avatar discountry commented on May 1, 2024

不好意思,这个怪我们的翻译不到位,题目原文为:

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.

huluoyang avatar huluoyang commented on May 1, 2024

image
@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.