* fix: Chinese test suite Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working. * fix: ran script, updated testStrings and solutions
2.1 KiB
2.1 KiB
id, title, challengeType, videoUrl, localeTitle
id | title | challengeType | videoUrl | localeTitle |
---|---|---|---|---|
587d7b8e367417b2b2512b5f | Pass Arguments to Avoid External Dependence in a Function | 1 | 传递参数以避免函数中的外部依赖 |
Description
fixedValue
,函数incrementer
将无法工作。函数式编程的另一个原则是始终明确声明您的依赖项。这意味着如果函数依赖于存在的变量或对象,则将该变量或对象作为参数直接传递给函数。这个原则有几个好的结果。该函数更容易测试,您确切知道它需要什么输入,并且它不依赖于程序中的任何其他内容。当您更改,删除或添加新代码时,这可以让您更有信心。你会知道你可以或不可以改变什么,你可以看到潜在陷阱的位置。最后,无论代码的哪一部分执行,函数总是会为同一组输入生成相同的输出。 Instructions
incrementer
函数以清楚地声明其依赖关系。编写incrementer
函数,使其获取参数,然后将值增加1。 Tests
tests:
- text: 您的函数<code>incrementer</code>不应更改<code>fixedValue</code>的值。
testString: assert(fixedValue === 4);
- text: 您的<code>incrementer</code>功能应该采用参数。
testString: assert(incrementer.length === 1);
- text: 您的<code>incrementer</code>函数应返回一个大于<code>fixedValue</code>值的值。
testString: assert(newValue === 5);
Challenge Seed
// the global variable
var fixedValue = 4;
// Add your code below this line
function incrementer () {
// Add your code above this line
}
var newValue = incrementer(fixedValue); // Should equal 5
console.log(fixedValue); // Should print 4
Solution
// solution required