fix: remove cn challenges already removed from eng
This commit is contained in:
committed by
Mrugesh Mohapatra
parent
c40eab94b7
commit
be3171169c
@ -1,61 +0,0 @@
|
|||||||
---
|
|
||||||
id: 587d7b8a367417b2b2512b4f
|
|
||||||
title: Write Concise Object Literal Declarations Using Simple Fields
|
|
||||||
challengeType: 1
|
|
||||||
videoUrl: ''
|
|
||||||
localeTitle: 使用简单字段编写简明对象文字声明
|
|
||||||
---
|
|
||||||
|
|
||||||
## Description
|
|
||||||
<section id="description"> ES6为轻松定义对象文字添加了一些很好的支持。请考虑以下代码: <blockquote> const getMousePosition =(x,y)=>({ <br> x:x, <br> y:y <br> }); </blockquote> <code>getMousePosition</code>是一个简单的函数,它返回一个包含两个字段的对象。 ES6提供了语法糖,以消除必须写入<code>x: x</code>的冗余。您可以简单地编写一次<code>x</code> ,它将被转换为<code>x: x</code> (或类似的东西)。这是从上面重写的相同函数使用这个新语法: <blockquote> const getMousePosition =(x,y)=>({x,y}); </blockquote></section>
|
|
||||||
|
|
||||||
## Instructions
|
|
||||||
<section id="instructions">使用带有对象文字的简单字段来创建和返回<code>Person</code>对象。 </section>
|
|
||||||
|
|
||||||
## Tests
|
|
||||||
<section id='tests'>
|
|
||||||
|
|
||||||
```yml
|
|
||||||
tests:
|
|
||||||
- text: '输出是<code>{name: "Zodiac Hasbro", age: 56, gender: "male"}</code> 。'
|
|
||||||
testString: assert(() => {const res={name:"Zodiac Hasbro",age:56,gender:"male"}; const person=createPerson("Zodiac Hasbro", 56, "male"); return Object.keys(person).every(k => person[k] === res[k]);});
|
|
||||||
- text: '不<code>:</code>被使用了。'
|
|
||||||
testString: getUserInput => assert(!getUserInput("index").match(/:/g));
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Challenge Seed
|
|
||||||
<section id='challengeSeed'>
|
|
||||||
|
|
||||||
<div id='js-seed'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
const createPerson = (name, age, gender) => {
|
|
||||||
"use strict";
|
|
||||||
// change code below this line
|
|
||||||
return {
|
|
||||||
name: name,
|
|
||||||
age: age,
|
|
||||||
gender: gender
|
|
||||||
};
|
|
||||||
// change code above this line
|
|
||||||
};
|
|
||||||
console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Solution
|
|
||||||
<section id='solution'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
// solution required
|
|
||||||
```
|
|
||||||
</section>
|
|
@ -1,100 +0,0 @@
|
|||||||
---
|
|
||||||
id: 5a24c314108439a4d403617f
|
|
||||||
title: Manage Updates with Lifecycle Methods
|
|
||||||
challengeType: 6
|
|
||||||
isRequired: false
|
|
||||||
videoUrl: ''
|
|
||||||
localeTitle: 使用生命周期方法管理更新
|
|
||||||
---
|
|
||||||
|
|
||||||
## Description
|
|
||||||
<section id="description">另一个生命周期方法是<code>componentWillReceiveProps()</code> ,只要组件正在接收新的道具就会调用它。此方法接收新的props作为参数,通常写为<code>nextProps</code> 。您可以使用此参数并与<code>this.props</code>进行比较,并在组件更新之前执行操作。例如,您可以在处理更新之前在本地调用<code>setState()</code> 。另一种方法是<code>componentDidUpdate()</code> ,并在组件重新渲染后立即调用。请注意,渲染和安装在组件生命周期中被视为不同的东西。首次加载页面时,将挂载所有组件,这是调用<code>componentWillMount()</code>和<code>componentDidMount()</code>位置。在此之后,随着状态的改变,组件会重新渲染自己。下一个挑战将更详细地介绍这一点。 </section>
|
|
||||||
|
|
||||||
## Instructions
|
|
||||||
<section id="instructions">子组件<code>Dialog</code>从其父组件<code>Controller</code>组件接收<code>message</code>道具。在<code>Dialog</code>组件中编写<code>componentWillReceiveProps()</code>方法,并将<code>this.props</code>和<code>nextProps</code>到控制台。您需要将<code>nextProps</code>作为参数传递给此方法,虽然可以将其命名为任何名称,但<code>nextProps</code>其命名为<code>nextProps</code> 。接下来,在<code>Dialog</code>组件中添加<code>componentDidUpdate()</code> ,并记录一条说明组件已更新的语句。此方法的工作方式类似于为您提供的<code>componentWillUpdate()</code> 。现在单击按钮更改消息并观察浏览器控制台。控制台语句的顺序显示调用方法的顺序。 <strong>注意:</strong>您需要将生命周期方法编写为普通函数而不是箭头函数来传递测试(将生命周期方法编写为箭头函数也没有优势)。 </section>
|
|
||||||
|
|
||||||
## Tests
|
|
||||||
<section id='tests'>
|
|
||||||
|
|
||||||
```yml
|
|
||||||
tests:
|
|
||||||
- text: <code>Controller</code>组件应将<code>Dialog</code>组件呈现为子组件。
|
|
||||||
testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(Controller)); return mockedComponent.find("Controller").length === 1 && mockedComponent.find("Dialog").length === 1; })(), "The <code>Controller</code> component should render the <code>Dialog</code> component as a child.");'
|
|
||||||
- text: <code>Dialog</code>组件中的<code>componentWillReceiveProps</code>方法应将<code>this.props</code>记录到控制台。
|
|
||||||
testString: 'assert((function() { const lifecycleChild = React.createElement(Dialog).type.prototype.componentWillReceiveProps.toString().replace(/ /g,""); return lifecycleChild.includes("console.log") && lifecycleChild.includes("this.props") })(), "The <code>componentWillReceiveProps</code> method in the <code>Dialog</code> component should log <code>this.props</code> to the console.");'
|
|
||||||
- text: <code>Dialog</code>组件中的<code>componentWillReceiveProps</code>方法应将<code>nextProps</code>记录到控制台。
|
|
||||||
testString: 'assert((function() { const lifecycleChild = React.createElement(Dialog).type.prototype.componentWillReceiveProps.toString().replace(/ /g,""); const nextPropsAsParameterTest = /componentWillReceiveProps(| *?= *?)(\(|)nextProps(\)|)( *?=> *?{| *?{|{)/; const nextPropsInConsoleLogTest = /console\.log\(.*?nextProps\b.*?\)/; return ( lifecycleChild.includes("console.log") && nextPropsInConsoleLogTest.test(lifecycleChild) && nextPropsAsParameterTest.test(lifecycleChild) ); })(), "The <code>componentWillReceiveProps</code> method in the <code>Dialog</code> component should log <code>nextProps</code> to the console.");'
|
|
||||||
- text: <code>Dialog</code>组件应调用<code>componentDidUpdate</code>方法并将消息记录到控制台。
|
|
||||||
testString: 'assert((function() { const lifecycleChild = React.createElement(Dialog).type.prototype.componentDidUpdate.toString().replace(/ /g,""); return lifecycleChild.length !== "undefined" && lifecycleChild.includes("console.log"); })(), "The <code>Dialog</code> component should call the <code>componentDidUpdate</code> method and log a message to the console.");'
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Challenge Seed
|
|
||||||
<section id='challengeSeed'>
|
|
||||||
|
|
||||||
<div id='jsx-seed'>
|
|
||||||
|
|
||||||
```jsx
|
|
||||||
class Dialog extends React.Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
}
|
|
||||||
componentWillUpdate() {
|
|
||||||
console.log('Component is about to update...');
|
|
||||||
}
|
|
||||||
// change code below this line
|
|
||||||
|
|
||||||
// change code above this line
|
|
||||||
render() {
|
|
||||||
return <h1>{this.props.message}</h1>
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Controller extends React.Component {
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
message: 'First Message'
|
|
||||||
};
|
|
||||||
this.changeMessage = this.changeMessage.bind(this);
|
|
||||||
}
|
|
||||||
changeMessage() {
|
|
||||||
this.setState({
|
|
||||||
message: 'Second Message'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
render() {
|
|
||||||
return (
|
|
||||||
<div>
|
|
||||||
<button onClick={this.changeMessage}>Update</button>
|
|
||||||
<Dialog message={this.state.message}/>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
### After Test
|
|
||||||
<div id='jsx-teardown'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
console.info('after the test');
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Solution
|
|
||||||
<section id='solution'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
// solution required
|
|
||||||
```
|
|
||||||
</section>
|
|
@ -1,75 +0,0 @@
|
|||||||
---
|
|
||||||
id: 587d8253367417b2b2512c6b
|
|
||||||
title: Remove from a Set
|
|
||||||
challengeType: 1
|
|
||||||
videoUrl: ''
|
|
||||||
localeTitle: 从集合中删除
|
|
||||||
---
|
|
||||||
|
|
||||||
## Description
|
|
||||||
<section id="description">在本练习中,我们将为我们的集创建一个删除函数。该函数应命名为<code>this.remove</code> 。此函数应接受一个值并检查它是否存在于集合中。如果是,请从集合中删除该值,然后返回true。否则,返回false。 </section>
|
|
||||||
|
|
||||||
## Instructions
|
|
||||||
<section id="instructions">
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Tests
|
|
||||||
<section id='tests'>
|
|
||||||
|
|
||||||
```yml
|
|
||||||
tests:
|
|
||||||
- text: 您的<code>Set</code>类应该有一个<code>remove</code>方法。
|
|
||||||
testString: 'assert((function(){var test = new Set(); return (typeof test.remove === "function")}()), "Your <code>Set</code> class should have a <code>remove</code> method.");'
|
|
||||||
- text: 您的<code>remove</code>方法应该只删除集合中存在的项目。
|
|
||||||
testString: 'assert.deepEqual((function(){var test = new Set(); test.add("a");test.add("b");test.remove("c"); return test.values(); })(), ["a", "b"], "Your <code>remove</code> method should only remove items that are present in the set.");'
|
|
||||||
- text: 您的<code>remove</code>方法应从集合中删除给定的项目。
|
|
||||||
testString: 'assert((function(){var test = new Set(); test.add("a");test.add("b");test.remove("a"); var vals = test.values(); return (vals[0] === "b" && vals.length === 1)}()), "Your <code>remove</code> method should remove the given item from the set.");'
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Challenge Seed
|
|
||||||
<section id='challengeSeed'>
|
|
||||||
|
|
||||||
<div id='js-seed'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
function Set() {
|
|
||||||
// the var collection will hold the set
|
|
||||||
var collection = [];
|
|
||||||
// this method will check for the presence of an element and return true or false
|
|
||||||
this.has = function(element) {
|
|
||||||
return (collection.indexOf(element) !== -1);
|
|
||||||
};
|
|
||||||
// this method will return all the values in the set
|
|
||||||
this.values = function() {
|
|
||||||
return collection;
|
|
||||||
};
|
|
||||||
// this method will add an element to the set
|
|
||||||
this.add = function(element) {
|
|
||||||
if(!this.has(element)){
|
|
||||||
collection.push(element);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
// change code below this line
|
|
||||||
// change code above this line
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Solution
|
|
||||||
<section id='solution'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
// solution required
|
|
||||||
```
|
|
||||||
</section>
|
|
@ -1,82 +0,0 @@
|
|||||||
---
|
|
||||||
id: 8d1923c8c441eddfaeb5bdef
|
|
||||||
title: Size of the Set
|
|
||||||
challengeType: 1
|
|
||||||
videoUrl: ''
|
|
||||||
localeTitle: 套装的大小
|
|
||||||
---
|
|
||||||
|
|
||||||
## Description
|
|
||||||
<section id="description">在本练习中,我们将为Set创建一个size函数。此函数应命名为<code>this.size</code> ,它应返回集合的大小。 </section>
|
|
||||||
|
|
||||||
## Instructions
|
|
||||||
<section id="instructions">
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Tests
|
|
||||||
<section id='tests'>
|
|
||||||
|
|
||||||
```yml
|
|
||||||
tests:
|
|
||||||
- text: 您的<code>Set</code>类应该有一个<code>size</code>方法。
|
|
||||||
testString: 'assert((function(){var test = new Set(); return (typeof test.size === "function")}()), "Your <code>Set</code> class should have a <code>size</code> method.");'
|
|
||||||
- text: <code>size</code>方法应返回集合中的元素数。
|
|
||||||
testString: 'assert((function(){var test = new Set(); test.add("a");test.add("b");test.remove("a");return (test.size() === 1)}()), "The <code>size</code> method should return the number of elements in the collection.");'
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Challenge Seed
|
|
||||||
<section id='challengeSeed'>
|
|
||||||
|
|
||||||
<div id='js-seed'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
function Set() {
|
|
||||||
// the var collection will hold the set
|
|
||||||
var collection = [];
|
|
||||||
// this method will check for the presence of an element and return true or false
|
|
||||||
this.has = function(element) {
|
|
||||||
return (collection.indexOf(element) !== -1);
|
|
||||||
};
|
|
||||||
// this method will return all the values in the set
|
|
||||||
this.values = function() {
|
|
||||||
return collection;
|
|
||||||
};
|
|
||||||
// this method will add an element to the set
|
|
||||||
this.add = function(element) {
|
|
||||||
if(!this.has(element)){
|
|
||||||
collection.push(element);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
// this method will remove an element from a set
|
|
||||||
this.remove = function(element) {
|
|
||||||
if(this.has(element)){
|
|
||||||
var index = collection.indexOf(element);
|
|
||||||
collection.splice(index,1);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
// change code below this line
|
|
||||||
// change code above this line
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Solution
|
|
||||||
<section id='solution'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
// solution required
|
|
||||||
```
|
|
||||||
</section>
|
|
@ -1,64 +0,0 @@
|
|||||||
---
|
|
||||||
title: GeneratorExponential
|
|
||||||
id: 5a23c84252665b21eecc7e7b
|
|
||||||
challengeType: 5
|
|
||||||
videoUrl: ''
|
|
||||||
localeTitle: GeneratorExponential
|
|
||||||
---
|
|
||||||
|
|
||||||
## Description
|
|
||||||
<section id="description">生成器是一个可执行实体(如函数或过程),它包含一次生成一个值序列的代码,这样每次调用生成器时,都会提供序列中的下一个值。生成器通常构建在协同程序或对象之上,以便“自然地”处理对象的内部状态。生成器通常用于序列可能无限的情况,并且可以在只有最小状态的情况下构造序列的下一个值。编写一个使用生成器生成正方形和立方体的函数。创建一个新的生成器,从正方形生成器中过滤所有多维数据集。该函数应返回已过滤生成器的\(n ^ {th} \)值。例如,对于\(n = 7 \),函数应该返回81,因为序列将是4,9,16,25,36,49,81。这里64被过滤掉了,因为它是一个立方体。 </section>
|
|
||||||
|
|
||||||
## Instructions
|
|
||||||
<section id="instructions">
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Tests
|
|
||||||
<section id='tests'>
|
|
||||||
|
|
||||||
```yml
|
|
||||||
tests:
|
|
||||||
- text: <code>exponentialGenerator</code>应该是一个函数。
|
|
||||||
testString: 'assert(typeof exponentialGenerator=="function","<code>exponentialGenerator</code> should be a function.");'
|
|
||||||
- text: <code>exponentialGenerator()</code>应该返回一个数字。
|
|
||||||
testString: 'assert(typeof exponentialGenerator(10)=="number","<code>exponentialGenerator()</code> should return a number.");'
|
|
||||||
- text: <code>exponentialGenerator(10)</code>应该返回<code>144</code> 。
|
|
||||||
testString: 'assert.equal(exponentialGenerator(10),144,"<code>exponentialGenerator(10)</code> should return <code>144</code>.");'
|
|
||||||
- text: <code>exponentialGenerator(12)</code>应该返回<code>196</code> 。
|
|
||||||
testString: 'assert.equal(exponentialGenerator(12),196,"<code>exponentialGenerator(12)</code> should return <code>196</code>.");'
|
|
||||||
- text: <code>exponentialGenerator(14)</code>应该返回<code>256</code> 。
|
|
||||||
testString: 'assert.equal(exponentialGenerator(14),256,"<code>exponentialGenerator(14)</code> should return <code>256</code>.");'
|
|
||||||
- text: <code>exponentialGenerator(20)</code>应该返回<code>484</code> 。
|
|
||||||
testString: 'assert.equal(exponentialGenerator(20),484,"<code>exponentialGenerator(20)</code> should return <code>484</code>.");'
|
|
||||||
- text: <code>exponentialGenerator(25)</code>应该返回<code>784</code> 。
|
|
||||||
testString: 'assert.equal(exponentialGenerator(25),784,"<code>exponentialGenerator(25)</code> should return <code>784</code>.");'
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Challenge Seed
|
|
||||||
<section id='challengeSeed'>
|
|
||||||
|
|
||||||
<div id='js-seed'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
function exponentialGenerator (n) {
|
|
||||||
// Good luck!
|
|
||||||
}
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</section>
|
|
||||||
|
|
||||||
## Solution
|
|
||||||
<section id='solution'>
|
|
||||||
|
|
||||||
```js
|
|
||||||
// solution required
|
|
||||||
```
|
|
||||||
</section>
|
|
Reference in New Issue
Block a user