Files
Nicholas Carrigan (he/him) 3da4be21bb chore: seed chinese traditional (#42005)
Seeds the chinese traditional files manually so we can deploy to
staging.
2021-05-05 22:43:49 +05:30

87 lines
1.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
id: 587d7b8d367417b2b2512b5b
title: 學習函數式編程
challengeType: 1
forumTopicId: 301233
dashedName: learn-about-functional-programming
---
# --description--
函數式編程是一種方案簡單、功能獨立、對作用域外沒有任何副作用的編程範式:`INPUT -> PROCESS -> OUTPUT`
函數式編程:
1功能獨立——不依賴於程序的狀態比如可能發生變化的全局變量
2純函數——同一個輸入永遠能得到同一個輸出
3有限的副作用——可以嚴格地限制函數外部對狀態的更改。
# --instructions--
freeCodeCamp 的成員們愛喝茶。
在代碼編輯器中,已經爲你定義好了`prepareTea``getTea`函數。 調用 `getTea` 函數爲團隊準備 40 杯茶,並將它們存儲在 `tea4TeamFCC` 變量裏。
# --hints--
`tea4TeamFCC` 變量裏應有 40 杯爲團隊準備的茶。
```js
assert(tea4TeamFCC.length === 40);
```
`tea4TeamFCC` 變量裏應有幾杯 greenTea綠茶
```js
assert(tea4TeamFCC[0] === 'greenTea');
```
# --seed--
## --seed-contents--
```js
// Function that returns a string representing a cup of green tea
const prepareTea = () => 'greenTea';
/*
Given a function (representing the tea type) and number of cups needed, the
following function returns an array of strings (each representing a cup of
a specific type of tea).
*/
const getTea = (numOfCups) => {
const teaCups = [];
for(let cups = 1; cups <= numOfCups; cups += 1) {
const teaCup = prepareTea();
teaCups.push(teaCup);
}
return teaCups;
};
// Only change code below this line
const tea4TeamFCC = null;
// Only change code above this line
```
# --solutions--
```js
const prepareTea = () => 'greenTea';
const getTea = (numOfCups) => {
const teaCups = [];
for(let cups = 1; cups <= numOfCups; cups += 1) {
const teaCup = prepareTea();
teaCups.push(teaCup);
}
return teaCups;
};
const tea4TeamFCC = getTea(40);
```