fix(i18n): update Chinese translation of JavaScript Algorithms and Da… (#38494)
Co-authored-by: Zhicheng Chen <chenzhicheng@dayuwuxian.com> Co-authored-by: S1ngS1ng <liuxing0514@gmail.com>
This commit is contained in:
@ -3,15 +3,21 @@ id: 56533eb9ac21ba0edf2244e2
|
|||||||
title: Caesars Cipher
|
title: Caesars Cipher
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
isRequired: true
|
isRequired: true
|
||||||
videoUrl: ''
|
forumTopicId: 16003
|
||||||
localeTitle: 凯撒密码
|
localeTitle: 凯撒密码
|
||||||
---
|
---
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id="description">最简单和最广为人知的<dfn>密码之一</dfn>是<code>Caesar cipher</code> ,也称为<code>shift cipher</code> 。在<code>shift cipher</code>中,字母的含义被移动一些设定量。一种常见的现代用途是<a href="https://en.wikipedia.org/wiki/ROT13" target="_blank">ROT13</a>密码,其中字母的值移动了13个位置。因此'A'''N','B'''O'等等。编写一个函数,它将<a href="https://en.wikipedia.org/wiki/ROT13" target="_blank">ROT13</a>编码的字符串作为输入并返回一个已解码的字符串。所有字母都是大写的。不要转换任何非字母字符(即空格,标点符号),但要传递它们。如果卡住,请记得使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。尝试配对程序。编写自己的代码。 </section>
|
<section id='description'>
|
||||||
|
<code>凯撒密码</code>是最简单和最广为人知的<dfn>密码之一</dfn>,也被称为<code>移位密码</code>。在<code>移位密码</code>中,明文中的字母通过按照一个固定数目进行偏移后被替换成新的字母。
|
||||||
|
<a href="https://en.wikipedia.org/wiki/ROT13" target='_blank'>ROT13</a> 是一个被广泛使用的编码技术,明文中的所有字母都被移动 13 位。因此,'A' ↔ 'N', 'B' ↔ 'O' 等等。
|
||||||
|
请编写一个函数,用于解码一个被 <a href="https://en.wikipedia.org/wiki/ROT13" target='_blank'>ROT13</a> 编码的字符串,然后返回解码后的结果。
|
||||||
|
所有解码后的字母都必须为字母大写。请不要解码非字母的字符(例如,空格、标点符号),但你需要在结果中保留它们。
|
||||||
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id="instructions">
|
<section id='instructions'>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
@ -19,13 +25,13 @@ localeTitle: 凯撒密码
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
tests:
|
tests:
|
||||||
- text: <code>rot13("SERR PBQR PNZC")</code>应解码为<code>FREE CODE CAMP</code>
|
- text: "<code>rot13('SERR PBQR PNZC')</code>应解码为<code>FREE CODE CAMP</code>。"
|
||||||
testString: assert(rot13("SERR PBQR PNZC") === "FREE CODE CAMP");
|
testString: assert(rot13("SERR PBQR PNZC") === "FREE CODE CAMP");
|
||||||
- text: <code>rot13("SERR CVMMN!")</code>应该解码为<code>FREE PIZZA!</code> <code>rot13("SERR CVMMN!")</code> <code>FREE PIZZA!</code>
|
- text: "<code>rot13('SERR CVMMN!')</code>应解码为<code>FREE PIZZA!</code>。"
|
||||||
testString: assert(rot13("SERR CVMMN!") === "FREE PIZZA!");
|
testString: assert(rot13("SERR CVMMN!") === "FREE PIZZA!");
|
||||||
- text: <code>rot13("SERR YBIR?")</code>应解码为<code>FREE LOVE?</code>
|
- text: "<code>rot13('SERR YBIR?')</code>应解码为<code>FREE LOVE?</code>。"
|
||||||
testString: assert(rot13("SERR YBIR?") === "FREE LOVE?");
|
testString: assert(rot13("SERR YBIR?") === "FREE LOVE?");
|
||||||
- text: <code>rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.")</code>应该在<code>rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.")</code>解码到<code>THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.</code>
|
- text: "<code>rot13('GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.')</code>应解码为<code>THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.</code>。"
|
||||||
testString: assert(rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.") === "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.");
|
testString: assert(rot13("GUR DHVPX OEBJA SBK WHZCF BIRE GUR YNML QBT.") === "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.");
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -45,7 +51,6 @@ function rot13(str) { // LBH QVQ VG!
|
|||||||
|
|
||||||
// Change the inputs below to test
|
// Change the inputs below to test
|
||||||
rot13("SERR PBQR PNZC");
|
rot13("SERR PBQR PNZC");
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -57,8 +62,33 @@ rot13("SERR PBQR PNZC");
|
|||||||
## Solution
|
## Solution
|
||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
var lookup = {
|
||||||
|
'A': 'N','B': 'O','C': 'P','D': 'Q',
|
||||||
|
'E': 'R','F': 'S','G': 'T','H': 'U',
|
||||||
|
'I': 'V','J': 'W','K': 'X','L': 'Y',
|
||||||
|
'M': 'Z','N': 'A','O': 'B','P': 'C',
|
||||||
|
'Q': 'D','R': 'E','S': 'F','T': 'G',
|
||||||
|
'U': 'H','V': 'I','W': 'J','X': 'K',
|
||||||
|
'Y': 'L','Z': 'M'
|
||||||
|
};
|
||||||
|
|
||||||
|
function rot13(encodedStr) {
|
||||||
|
var codeArr = encodedStr.split(""); // String to Array
|
||||||
|
var decodedArr = []; // Your Result goes here
|
||||||
|
// Only change code below this line
|
||||||
|
|
||||||
|
decodedArr = codeArr.map(function(letter) {
|
||||||
|
if(lookup.hasOwnProperty(letter)) {
|
||||||
|
letter = lookup[letter];
|
||||||
|
}
|
||||||
|
return letter;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Only change code above this line
|
||||||
|
return decodedArr.join(""); // Array to String
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
/section>
|
</section>
|
||||||
|
@ -3,15 +3,24 @@ id: aa2e6f85cab2ab736c9a9b24
|
|||||||
title: Cash Register
|
title: Cash Register
|
||||||
isRequired: true
|
isRequired: true
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
videoUrl: ''
|
forumTopicId: 16012
|
||||||
localeTitle: 收银机
|
localeTitle: 收银机
|
||||||
---
|
---
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id="description">设计一个收银抽屉功能<code>checkCashRegister()</code> ,它接受购买价格作为第一个参数( <code>price</code> ),支付作为第二个参数( <code>cash</code> ),以及现金抽屉( <code>cid</code> )作为第三个参数。 <code>cid</code>是列出可用货币的2D数组。 <code>checkCashRegister()</code>函数应始终返回带有<code>status</code>键和<code>change</code>键的对象。返回<code>{status: "INSUFFICIENT_FUNDS", change: []}</code>如果出现的现金少于到期的更改,或者如果您无法返回确切的更改。返回<code>{status: "CLOSED", change: [...]}</code>使用cash-in-drawer作为密钥<code>change</code>的值,如果它等于更改到期。否则,返回<code>{status: "OPEN", change: [...]}</code> ,以硬币和账单中的更改到期,按从最高到最低的顺序排序,作为<code>change</code>密钥的值。如果卡住,请记得使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。尝试配对程序。编写自己的代码。 <table class="table table-striped"><tbody><tr><th>货币单位</th><th>量</th></tr><tr><td>一分钱</td><td> 0.01美元(PENNY) </td></tr><tr><td>镍</td><td> 0.05美元(NICKEL) </td></tr><tr><td>十分钱</td><td> 0.1美元(DIME) </td></tr><tr><td> 25美分硬币</td><td> 0.25美元(季) </td></tr><tr><td>美元</td><td> 1美元(美元) </td></tr><tr><td>五美元</td><td> 5美元(五) </td></tr><tr><td>十美元</td><td> 10美元(10日) </td></tr><tr><td>二十美元</td><td> 20美元(二十美元) </td></tr><tr><td>一百元</td><td> 100美元(一百) </td></tr></tbody></table></section>
|
<section id='description'>
|
||||||
|
编写一个用于收银机的函数<code>checkCashRegister()</code>,传入售价为第一个参数(<code>price</code>)、支付金额为第二个参数(<code>cash</code>)、收银机內的金额为第三个参数(<code>cid</code>)。
|
||||||
|
<code>cid</code>是包含货币面值的二维数组。
|
||||||
|
函数<code>checkCashRegister()</code>必须返回含有<code>status</code>键值和<code>change</code>键值的对象。
|
||||||
|
如果收银机內的金额少于应找回的零钱数,或者你无法返回确切的数目时,返回<code>{status: "INSUFFICIENT_FUNDS", change: []}</code>。
|
||||||
|
如果收银机內的金额等于应找回的零钱数,返回<code>{status: "CLOSED", change: [...]}</code>,其中<code>change</code>键值是收银机內的金额。
|
||||||
|
否则,返回<code>{status: "OPEN", change: [...]}</code>,其中<code>change</code>键值是应找回的零钱数,并且它的面值由高到低排序。
|
||||||
|
<table class='table table-striped'><tr><th>货币单位</th><th>面值</th></tr><tr><td>Penny</td><td>$0.01 (PENNY)</td></tr><tr><td>Nickel</td><td>$0.05 (NICKEL)</td></tr><tr><td>Dime</td><td>$0.1 (DIME)</td></tr><tr><td>Quarter</td><td>$0.25 (QUARTER)</td></tr><tr><td>Dollar</td><td>$1 (DOLLAR)</td></tr><tr><td>Five Dollars</td><td>$5 (FIVE)</td></tr><tr><td>Ten Dollars</td><td>$10 (TEN)</td></tr><tr><td>Twenty Dollars</td><td>$20 (TWENTY)</td></tr><tr><td>One-hundred Dollars</td><td>$100 (ONE HUNDRED)</td></tr></table>
|
||||||
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id="instructions">
|
<section id='instructions'>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
@ -19,17 +28,17 @@ localeTitle: 收银机
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
tests:
|
tests:
|
||||||
- text: '<code>checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])</code>应该返回一个物体。'
|
- text: "<code>checkCashRegister(19.5, 20, [['PENNY', 1.01], ['NICKEL', 2.05], ['DIME', 3.1], ['QUARTER', 4.25], ['ONE', 90], ['FIVE', 55], ['TEN', 20], ['TWENTY', 60], ['ONE HUNDRED', 100]])</code>应该返回一个对象。"
|
||||||
testString: assert.deepEqual(Object.prototype.toString.call(checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])), '[object Object]');
|
testString: assert.deepEqual(Object.prototype.toString.call(checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])), '[object Object]');
|
||||||
- text: '<code>checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])</code>应返回<code>{status: "OPEN", change: [["QUARTER", 0.5]]}</code> 。'
|
- text: '<code>checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])</code>应该返回<code>{status: "OPEN", change: [["QUARTER", 0.5]]}</code>。'
|
||||||
testString: 'assert.deepEqual(checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]), {status: "OPEN", change: [["QUARTER", 0.5]]});'
|
testString: 'assert.deepEqual(checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]), {status: "OPEN", change: [["QUARTER", 0.5]]});'
|
||||||
- text: '<code>checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])</code>应返回<code>{status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]}</code> 。'
|
- text: '<code>checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]])</code>应该返回<code>{status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]}</code>。'
|
||||||
testString: 'assert.deepEqual(checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]), {status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]});'
|
testString: 'assert.deepEqual(checkCashRegister(3.26, 100, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]), {status: "OPEN", change: [["TWENTY", 60], ["TEN", 20], ["FIVE", 15], ["ONE", 1], ["QUARTER", 0.5], ["DIME", 0.2], ["PENNY", 0.04]]});'
|
||||||
- text: '<code>checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])</code>应返回<code>{status: "INSUFFICIENT_FUNDS", change: []}</code> 。'
|
- text: '<code>checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])</code>应该返回<code>{status: "INSUFFICIENT_FUNDS", change: []}</code>。'
|
||||||
testString: 'assert.deepEqual(checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]), {status: "INSUFFICIENT_FUNDS", change: []});'
|
testString: 'assert.deepEqual(checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]), {status: "INSUFFICIENT_FUNDS", change: []});'
|
||||||
- text: '<code>checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])</code>应返回<code>{status: "INSUFFICIENT_FUNDS", change: []}</code> 。'
|
- text: '<code>checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])</code>应该返回<code>{status: "INSUFFICIENT_FUNDS", change: []}</code>。'
|
||||||
testString: 'assert.deepEqual(checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]), {status: "INSUFFICIENT_FUNDS", change: []});'
|
testString: 'assert.deepEqual(checkCashRegister(19.5, 20, [["PENNY", 0.01], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 1], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]), {status: "INSUFFICIENT_FUNDS", change: []});'
|
||||||
- text: '<code>checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])</code>应返回<code>{status: "CLOSED", change: [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]}</code> 。'
|
- text: '<code>checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]])</code>应该返回<code>{status: "CLOSED", change: [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]}</code>。'
|
||||||
testString: 'assert.deepEqual(checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]), {status: "CLOSED", change: [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]});'
|
testString: 'assert.deepEqual(checkCashRegister(19.5, 20, [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]), {status: "CLOSED", change: [["PENNY", 0.5], ["NICKEL", 0], ["DIME", 0], ["QUARTER", 0], ["ONE", 0], ["FIVE", 0], ["TEN", 0], ["TWENTY", 0], ["ONE HUNDRED", 0]]});'
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -60,7 +69,6 @@ function checkCashRegister(price, cash, cid) {
|
|||||||
// ["ONE HUNDRED", 100]]
|
// ["ONE HUNDRED", 100]]
|
||||||
|
|
||||||
checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
|
checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], ["QUARTER", 4.25], ["ONE", 90], ["FIVE", 55], ["TEN", 20], ["TWENTY", 60], ["ONE HUNDRED", 100]]);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -72,8 +80,58 @@ checkCashRegister(19.5, 20, [["PENNY", 1.01], ["NICKEL", 2.05], ["DIME", 3.1], [
|
|||||||
## Solution
|
## Solution
|
||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
var denom = [
|
||||||
|
{ name: 'ONE HUNDRED', val: 100},
|
||||||
|
{ name: 'TWENTY', val: 20},
|
||||||
|
{ name: 'TEN', val: 10},
|
||||||
|
{ name: 'FIVE', val: 5},
|
||||||
|
{ name: 'ONE', val: 1},
|
||||||
|
{ name: 'QUARTER', val: 0.25},
|
||||||
|
{ name: 'DIME', val: 0.1},
|
||||||
|
{ name: 'NICKEL', val: 0.05},
|
||||||
|
{ name: 'PENNY', val: 0.01}
|
||||||
|
];
|
||||||
|
|
||||||
|
function checkCashRegister(price, cash, cid) {
|
||||||
|
var output = {status: null, change: []};
|
||||||
|
var change = cash - price;
|
||||||
|
var register = cid.reduce(function(acc, curr) {
|
||||||
|
acc.total += curr[1];
|
||||||
|
acc[curr[0]] = curr[1];
|
||||||
|
return acc;
|
||||||
|
}, {total: 0});
|
||||||
|
if(register.total === change) {
|
||||||
|
output.status = 'CLOSED';
|
||||||
|
output.change = cid;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
if(register.total < change) {
|
||||||
|
output.status = 'INSUFFICIENT_FUNDS';
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
var change_arr = denom.reduce(function(acc, curr) {
|
||||||
|
var value = 0;
|
||||||
|
while(register[curr.name] > 0 && change >= curr.val) {
|
||||||
|
change -= curr.val;
|
||||||
|
register[curr.name] -= curr.val;
|
||||||
|
value += curr.val;
|
||||||
|
change = Math.round(change * 100) / 100;
|
||||||
|
}
|
||||||
|
if(value > 0) {
|
||||||
|
acc.push([ curr.name, value ]);
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, []);
|
||||||
|
if(change_arr.length < 1 || change > 0) {
|
||||||
|
output.status = 'INSUFFICIENT_FUNDS';
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
output.status = 'OPEN';
|
||||||
|
output.change = change_arr;
|
||||||
|
return output;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
/section>
|
</section>
|
||||||
|
@ -3,15 +3,22 @@ id: aaa48de84e1ecc7c742e1124
|
|||||||
title: Palindrome Checker
|
title: Palindrome Checker
|
||||||
isRequired: true
|
isRequired: true
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
videoUrl: ''
|
forumTopicId: 16004
|
||||||
localeTitle: 回文检查
|
localeTitle: 回文检查器
|
||||||
---
|
---
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id="description">如果给定的字符串是回文,则返回<code>true</code> 。否则,返回<code>false</code> 。 <dfn>回文</dfn>是一个单词或句子,其拼写方式与前后相同,忽略标点符号,大小写和间距。 <strong>注意</strong> <br>您需要删除<strong>所有非字母数字字符</strong> (标点符号,空格和符号)并将所有内容转换为相同的大小写(小写或大写)以检查回文。我们会通过字符串具有不同的格式,如<code>"racecar"</code> , <code>"RaceCar"</code>和<code>"race CAR"</code>等等。我们还将传递带有特殊符号的字符串,例如<code>"2A3*3a2"</code> , <code>"2A3 3a2"</code>和<code>"2_A3*3#A2"</code> 。如果卡住,请记得使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。编写自己的代码。 </section>
|
<section id='description'>
|
||||||
|
如果给定的一个字符串是回文,那么返回<code>true</code>,否则返回<code>false</code>。
|
||||||
|
<dfn>palindrome(回文)</dfn>,指在忽略标点符号、大小写和空格的前提下,正着读和反着读一模一样。
|
||||||
|
<strong>注意:</strong><br>检查回文时,你需要先除去<strong>所有非字母数字的字符</strong>(标点、空格和符号)并且将所有字符转换成字母大写或字母小写。
|
||||||
|
我们将会传入不同格式的字符串,例如:<code>"racecar"</code>、<code>"RaceCar"</code>、<code>"race CAR"</code>等等。
|
||||||
|
我们也会传入一些包含特殊符号的字符串,例如<code>"2A3*3a2"</code>,<code>"2A3 3a2"</code>和<code>"2_A3*3#A2"</code>。
|
||||||
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id="instructions">
|
<section id='instructions'>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
@ -19,31 +26,31 @@ localeTitle: 回文检查
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
tests:
|
tests:
|
||||||
- text: <code>palindrome("eye")</code>应该返回一个布尔值。
|
- text: "<code>palindrome('eye')</code>应该返回一个布尔值。"
|
||||||
testString: assert(typeof palindrome("eye") === "boolean");
|
testString: assert(typeof palindrome("eye") === "boolean");
|
||||||
- text: <code>palindrome("eye")</code>应该返回true。
|
- text: "<code>palindrome('eye')</code>应该返回 true。"
|
||||||
testString: assert(palindrome("eye") === true);
|
testString: assert(palindrome("eye") === true);
|
||||||
- text: <code>palindrome("_eye")</code>应该返回true。
|
- text: "<code>palindrome('_eye')</code>应该返回 true。"
|
||||||
testString: assert(palindrome("_eye") === true);
|
testString: assert(palindrome("_eye") === true);
|
||||||
- text: <code>palindrome("race car")</code>应该返回true。
|
- text: "<code>palindrome('race car')</code>应该返回 true。"
|
||||||
testString: assert(palindrome("race car") === true);
|
testString: assert(palindrome("race car") === true);
|
||||||
- text: <code>palindrome("not a palindrome")</code>应该返回false。
|
- text: "<code>palindrome('not a palindrome')</code>应该返回 false。"
|
||||||
testString: assert(palindrome("not a palindrome") === false);
|
testString: assert(palindrome("not a palindrome") === false);
|
||||||
- text: '<code>palindrome("A man, a plan, a canal. Panama")</code>应该回归真实。'
|
- text: "<code>palindrome('A man, a plan, a canal. Panama')</code>应该返回 true。"
|
||||||
testString: assert(palindrome("A man, a plan, a canal. Panama") === true);
|
testString: assert(palindrome("A man, a plan, a canal. Panama") === true);
|
||||||
- text: <code>palindrome("never odd or even")</code>应该返回true。
|
- text: "<code>palindrome('never odd or even')</code>应该返回 true。"
|
||||||
testString: assert(palindrome("never odd or even") === true);
|
testString: assert(palindrome("never odd or even") === true);
|
||||||
- text: <code>palindrome("nope")</code>应该返回false。
|
- text: "<code>palindrome('nope')</code>应该返回 false。"
|
||||||
testString: assert(palindrome("nope") === false);
|
testString: assert(palindrome("nope") === false);
|
||||||
- text: <code>palindrome("almostomla")</code>应该返回false。
|
- text: "<code>palindrome('almostomla')</code>应该返回 false。"
|
||||||
testString: assert(palindrome("almostomla") === false);
|
testString: assert(palindrome("almostomla") === false);
|
||||||
- text: '<code>palindrome("My age is 0, 0 si ega ym.")</code>应该返回true。'
|
- text: "<code>palindrome('My age is 0, 0 si ega ym.')</code>应该返回 true。"
|
||||||
testString: assert(palindrome("My age is 0, 0 si ega ym.") === true);
|
testString: assert(palindrome("My age is 0, 0 si ega ym.") === true);
|
||||||
- text: <code>palindrome("1 eye for of 1 eye.")</code>应该返回假。
|
- text: "<code>palindrome('1 eye for of 1 eye.')</code>应该返回 false。"
|
||||||
testString: assert(palindrome("1 eye for of 1 eye.") === false);
|
testString: assert(palindrome("1 eye for of 1 eye.") === false);
|
||||||
- text: '<code>palindrome("0_0 (: /-\ :) 0-0")</code>应该返回true。'
|
- text: '<code>palindrome("0_0 (: /-\ :) 0-0")</code>应该返回 true。'
|
||||||
testString: 'assert(palindrome("0_0 (: /-\ :) 0-0") === true);'
|
testString: 'assert(palindrome("0_0 (: /-\ :) 0-0") === true);'
|
||||||
- text: <code>palindrome("five|\_/|four")</code>应该返回false。
|
- text: "<code>palindrome('five|\_/|four')</code>应该返回 false。"
|
||||||
testString: assert(palindrome("five|\_/|four") === false);
|
testString: assert(palindrome("five|\_/|four") === false);
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -64,7 +71,6 @@ function palindrome(str) {
|
|||||||
|
|
||||||
|
|
||||||
palindrome("eye");
|
palindrome("eye");
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -76,8 +82,17 @@ palindrome("eye");
|
|||||||
## Solution
|
## Solution
|
||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
function palindrome(str) {
|
||||||
|
var string = str.toLowerCase().split(/[^A-Za-z0-9]/gi).join('');
|
||||||
|
var aux = string.split('');
|
||||||
|
if (aux.join('') === aux.reverse().join('')){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
/section>
|
</section>
|
||||||
|
@ -3,15 +3,19 @@ id: a7f4d8f2483413a6ce226cac
|
|||||||
title: Roman Numeral Converter
|
title: Roman Numeral Converter
|
||||||
isRequired: true
|
isRequired: true
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
videoUrl: ''
|
forumTopicId: 16044
|
||||||
localeTitle: 罗马数字转换器
|
localeTitle: 罗马数字转换器
|
||||||
---
|
---
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id="description">将给定数字转换为罗马数字。所有<a href="http://www.mathsisfun.com/roman-numerals.html" target="_blank">罗马数字</a>答案都应以大写字母提供。如果卡住,请记得使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。尝试配对程序。编写自己的代码。 </section>
|
<section id='description'>
|
||||||
|
把传入的数字转变为罗马数字。
|
||||||
|
转换后的<a href="http://www.mathsisfun.com/roman-numerals.html" target="_blank">罗马数字</a>字母必须都是大写。
|
||||||
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id="instructions">
|
<section id='instructions'>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
@ -19,57 +23,57 @@ localeTitle: 罗马数字转换器
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
tests:
|
tests:
|
||||||
- text: <code>convertToRoman(2)</code>应该返回“II”。
|
- text: "<code>convertToRoman(2)</code>应该返回 'II'。"
|
||||||
testString: assert.deepEqual(convertToRoman(2), "II");
|
testString: assert.deepEqual(convertToRoman(2), "II");
|
||||||
- text: <code>convertToRoman(3)</code>应该返回“III”。
|
- text: "<code>convertToRoman(3)</code>应该返回 'III'。"
|
||||||
testString: assert.deepEqual(convertToRoman(3), "III");
|
testString: assert.deepEqual(convertToRoman(3), "III");
|
||||||
- text: <code>convertToRoman(4)</code>应该返回“IV”。
|
- text: "<code>convertToRoman(4)</code>应该返回 'IV'。"
|
||||||
testString: assert.deepEqual(convertToRoman(4), "IV");
|
testString: assert.deepEqual(convertToRoman(4), "IV");
|
||||||
- text: <code>convertToRoman(5)</code>应该返回“V”。
|
- text: "<code>convertToRoman(5)</code>应该返回 'V'。"
|
||||||
testString: assert.deepEqual(convertToRoman(5), "V");
|
testString: assert.deepEqual(convertToRoman(5), "V");
|
||||||
- text: <code>convertToRoman(9)</code>应该返回“IX”。
|
- text: "<code>convertToRoman(9)</code>应该返回 'IX'。"
|
||||||
testString: assert.deepEqual(convertToRoman(9), "IX");
|
testString: assert.deepEqual(convertToRoman(9), "IX");
|
||||||
- text: <code>convertToRoman(12)</code>应返回“XII”。
|
- text: "<code>convertToRoman(12)</code>应该返回 'XII'。"
|
||||||
testString: assert.deepEqual(convertToRoman(12), "XII");
|
testString: assert.deepEqual(convertToRoman(12), "XII");
|
||||||
- text: <code>convertToRoman(16)</code>应返回“XVI”。
|
- text: "<code>convertToRoman(16)</code>应该返回 'XVI'。"
|
||||||
testString: assert.deepEqual(convertToRoman(16), "XVI");
|
testString: assert.deepEqual(convertToRoman(16), "XVI");
|
||||||
- text: <code>convertToRoman(29)</code>应该返回“XXIX”。
|
- text: "<code>convertToRoman(29)</code>应该返回 'XXIX'。"
|
||||||
testString: assert.deepEqual(convertToRoman(29), "XXIX");
|
testString: assert.deepEqual(convertToRoman(29), "XXIX");
|
||||||
- text: <code>convertToRoman(44)</code>应该返回“XLIV”。
|
- text: "<code>convertToRoman(44)</code>应该返回 'XLIV'。"
|
||||||
testString: assert.deepEqual(convertToRoman(44), "XLIV");
|
testString: assert.deepEqual(convertToRoman(44), "XLIV");
|
||||||
- text: <code>convertToRoman(45)</code>应该返回“XLV”
|
- text: "<code>convertToRoman(45)</code>应该返回 'XLV'。"
|
||||||
testString: assert.deepEqual(convertToRoman(45), "XLV");
|
testString: assert.deepEqual(convertToRoman(45), "XLV");
|
||||||
- text: <code>convertToRoman(68)</code>应返回“LXVIII”
|
- text: "<code>convertToRoman(68)</code>应该返回 'LXVIII'。"
|
||||||
testString: assert.deepEqual(convertToRoman(68), "LXVIII");
|
testString: assert.deepEqual(convertToRoman(68), "LXVIII");
|
||||||
- text: <code>convertToRoman(83)</code>应返回“LXXXIII”
|
- text: "<code>convertToRoman(83)</code>应该返回 'LXXXIII'。"
|
||||||
testString: assert.deepEqual(convertToRoman(83), "LXXXIII");
|
testString: assert.deepEqual(convertToRoman(83), "LXXXIII");
|
||||||
- text: <code>convertToRoman(97)</code>应该返回“XCVII”
|
- text: "<code>convertToRoman(97)</code>应该返回 'XCVII'。"
|
||||||
testString: assert.deepEqual(convertToRoman(97), "XCVII");
|
testString: assert.deepEqual(convertToRoman(97), "XCVII");
|
||||||
- text: <code>convertToRoman(99)</code>应返回“XCIX”
|
- text: "<code>convertToRoman(99)</code>应该返回 'XCIX'。"
|
||||||
testString: assert.deepEqual(convertToRoman(99), "XCIX");
|
testString: assert.deepEqual(convertToRoman(99), "XCIX");
|
||||||
- text: <code>convertToRoman(400)</code>应返回“CD”
|
- text: "<code>convertToRoman(400)</code>应该返回 'CD'。"
|
||||||
testString: assert.deepEqual(convertToRoman(400), "CD");
|
testString: assert.deepEqual(convertToRoman(400), "CD");
|
||||||
- text: <code>convertToRoman(500)</code>应返回“D”
|
- text: "<code>convertToRoman(500)</code>应该返回 'D'。"
|
||||||
testString: assert.deepEqual(convertToRoman(500), "D");
|
testString: assert.deepEqual(convertToRoman(500), "D");
|
||||||
- text: <code>convertToRoman(501)</code>应返回“DI”
|
- text: "<code>convertToRoman(501)</code>应该返回 'DI'。"
|
||||||
testString: assert.deepEqual(convertToRoman(501), "DI");
|
testString: assert.deepEqual(convertToRoman(501), "DI");
|
||||||
- text: <code>convertToRoman(649)</code>应返回“DCXLIX”
|
- text: "<code>convertToRoman(649)</code>应该返回 'DCXLIX'。"
|
||||||
testString: assert.deepEqual(convertToRoman(649), "DCXLIX");
|
testString: assert.deepEqual(convertToRoman(649), "DCXLIX");
|
||||||
- text: <code>convertToRoman(798)</code>应返回“DCCXCVIII”
|
- text: "<code>convertToRoman(798)</code>应该返回 'DCCXCVIII'。"
|
||||||
testString: assert.deepEqual(convertToRoman(798), "DCCXCVIII");
|
testString: assert.deepEqual(convertToRoman(798), "DCCXCVIII");
|
||||||
- text: <code>convertToRoman(891)</code>应返回“DCCCXCI”
|
- text: "<code>convertToRoman(891)</code>应该返回 'DCCCXCI'。"
|
||||||
testString: assert.deepEqual(convertToRoman(891), "DCCCXCI");
|
testString: assert.deepEqual(convertToRoman(891), "DCCCXCI");
|
||||||
- text: <code>convertToRoman(1000)</code>应该返回“M”
|
- text: "<code>convertToRoman(1000)</code>应该返回 'M'。"
|
||||||
testString: assert.deepEqual(convertToRoman(1000), "M");
|
testString: assert.deepEqual(convertToRoman(1000), "M");
|
||||||
- text: <code>convertToRoman(1004)</code>应返回“MIV”
|
- text: "<code>convertToRoman(1004)</code>应该返回 'MIV'。"
|
||||||
testString: assert.deepEqual(convertToRoman(1004), "MIV");
|
testString: assert.deepEqual(convertToRoman(1004), "MIV");
|
||||||
- text: <code>convertToRoman(1006)</code>应返回“MVI”
|
- text: "<code>convertToRoman(1006)</code>应该返回 'MVI'。"
|
||||||
testString: assert.deepEqual(convertToRoman(1006), "MVI");
|
testString: assert.deepEqual(convertToRoman(1006), "MVI");
|
||||||
- text: <code>convertToRoman(1023)</code>应返回“MXXIII”
|
- text: "<code>convertToRoman(1023)</code>应该返回 'MXXIII'。"
|
||||||
testString: assert.deepEqual(convertToRoman(1023), "MXXIII");
|
testString: assert.deepEqual(convertToRoman(1023), "MXXIII");
|
||||||
- text: <code>convertToRoman(2014)</code>应返回“MMXIV”
|
- text: "<code>convertToRoman(2014)</code>应该返回 'MMXIV'。"
|
||||||
testString: assert.deepEqual(convertToRoman(2014), "MMXIV");
|
testString: assert.deepEqual(convertToRoman(2014), "MMXIV");
|
||||||
- text: <code>convertToRoman(3999)</code>应返回“MMMCMXCIX”
|
- text: "<code>convertToRoman(3999)</code>应该返回 'MMMCMXCIX'。"
|
||||||
testString: assert.deepEqual(convertToRoman(3999), "MMMCMXCIX");
|
testString: assert.deepEqual(convertToRoman(3999), "MMMCMXCIX");
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -87,7 +91,6 @@ function convertToRoman(num) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
convertToRoman(36);
|
convertToRoman(36);
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -99,8 +102,20 @@ convertToRoman(36);
|
|||||||
## Solution
|
## Solution
|
||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
function convertToRoman(num) {
|
||||||
|
var ref = [['M', 1000], ['CM', 900], ['D', 500], ['CD', 400], ['C', 100], ['XC', 90], ['L', 50], ['XL', 40], ['X', 10], ['IX', 9], ['V', 5], ['IV', 4], ['I', 1]];
|
||||||
|
var res = [];
|
||||||
|
ref.forEach(function(p) {
|
||||||
|
while (num >= p[1]) {
|
||||||
|
res.push(p[0]);
|
||||||
|
num -= p[1];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return res.join('');
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
/section>
|
|
||||||
|
</section>
|
||||||
|
@ -3,15 +3,21 @@ id: aff0395860f5d3034dc0bfc9
|
|||||||
title: Telephone Number Validator
|
title: Telephone Number Validator
|
||||||
challengeType: 5
|
challengeType: 5
|
||||||
isRequired: true
|
isRequired: true
|
||||||
videoUrl: ''
|
forumTopicId: 16090
|
||||||
localeTitle: 电话号码验证器
|
localeTitle: 电话号码验证器
|
||||||
---
|
---
|
||||||
|
|
||||||
## Description
|
## Description
|
||||||
<section id="description">如果传递的字符串看起来像有效的美国电话号码,则返回<code>true</code> 。用户可以按照他们选择的方式填写表单字段,只要其具有有效美国号码的格式即可。以下是美国数字的有效格式示例(有关其他变体,请参阅下面的测试): <blockquote> 555-555-5555 <br> (555)555-5555 <br> (555)555-5555 <br> 555 555 5555 <br> 5555555555 <br> 1 555 555 5555 </blockquote>对于此挑战,您将看到一个字符串,如<code>800-692-7753</code>或<code>8oo-six427676;laskdjf</code> 。您的工作是根据上面提供的任何格式组合验证或拒绝美国电话号码。区号是必需的。如果提供了国家/地区代码,则必须确认国家/地区代码为<code>1</code> 。如果字符串是有效的美国电话号码,则返回<code>true</code> ;否则返回<code>false</code> 。如果卡住,请记得使用<a href="https://forum.freecodecamp.org/t/how-to-get-help-when-you-are-stuck-coding/19514" target="_blank">Read-Search-Ask</a> 。尝试配对程序。编写自己的代码。 </section>
|
<section id='description'>
|
||||||
|
如果传入的字符串是一个有效的美国电话号码格式,则返回<code>true</code>。
|
||||||
|
只要是有效的美国电话号码的格式,用户可以按照他们的方式填写表单中的电话号码。以下是一些正确的例子(其他格式变形请参考以下例子):
|
||||||
|
<blockquote>555-555-5555<br>(555)555-5555<br>(555) 555-5555<br>555 555 5555<br>5555555555<br>1 555 555 5555</blockquote>
|
||||||
|
在这个挑战中,你将会看到例如<code>800-692-7753</code>或者<code>8oo-six427676;laskdjf</code>的号码。你的任务是根据上面不同的格式组合,判断它是否美国号码。区号是必须的。如果提供国家代码,则必须确认国家代码为<code>1</code>。如果这是有效的美国电话就返回<code>true</code>,否则返回<code>false</code>。
|
||||||
|
</section>
|
||||||
|
|
||||||
## Instructions
|
## Instructions
|
||||||
<section id="instructions">
|
<section id='instructions'>
|
||||||
|
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
## Tests
|
## Tests
|
||||||
@ -19,59 +25,59 @@ localeTitle: 电话号码验证器
|
|||||||
|
|
||||||
```yml
|
```yml
|
||||||
tests:
|
tests:
|
||||||
- text: <code>telephoneCheck("555-555-5555")</code>应该返回一个布尔值。
|
- text: "<code>telephoneCheck('555-555-5555')</code>应该返回布尔值。"
|
||||||
testString: assert(typeof telephoneCheck("555-555-5555") === "boolean");
|
testString: assert(typeof telephoneCheck("555-555-5555") === "boolean");
|
||||||
- text: <code>telephoneCheck("1 555-555-5555")</code>应该返回true。
|
- text: "<code>telephoneCheck('1 555-555-5555')</code>应该返回 true。"
|
||||||
testString: assert(telephoneCheck("1 555-555-5555") === true);
|
testString: assert(telephoneCheck("1 555-555-5555") === true);
|
||||||
- text: <code>telephoneCheck("1 (555) 555-5555")</code>应该返回true。
|
- text: "<code>telephoneCheck('1 (555) 555-5555')</code>应该返回 true。"
|
||||||
testString: assert(telephoneCheck("1 (555) 555-5555") === true);
|
testString: assert(telephoneCheck("1 (555) 555-5555") === true);
|
||||||
- text: <code>telephoneCheck("5555555555")</code>应该返回true。
|
- text: "<code>telephoneCheck('5555555555')</code>应该返回 true。"
|
||||||
testString: assert(telephoneCheck("5555555555") === true);
|
testString: assert(telephoneCheck("5555555555") === true);
|
||||||
- text: <code>telephoneCheck("555-555-5555")</code>应该返回true。
|
- text: "<code>telephoneCheck('555-555-5555')</code>应该返回 true。"
|
||||||
testString: assert(telephoneCheck("555-555-5555") === true);
|
testString: assert(telephoneCheck("555-555-5555") === true);
|
||||||
- text: <code>telephoneCheck("(555)555-5555")</code>应该返回true。
|
- text: "<code>telephoneCheck('(555)555-5555')</code>应该返回 true。"
|
||||||
testString: assert(telephoneCheck("(555)555-5555") === true);
|
testString: assert(telephoneCheck("(555)555-5555") === true);
|
||||||
- text: <code>telephoneCheck("1(555)555-5555")</code>应该返回true。
|
- text: "<code>telephoneCheck('1(555)555-5555')</code>应该返回 true。"
|
||||||
testString: assert(telephoneCheck("1(555)555-5555") === true);
|
testString: assert(telephoneCheck("1(555)555-5555") === true);
|
||||||
- text: <code>telephoneCheck("555-5555")</code>应该返回false。
|
- text: "<code>telephoneCheck('555-5555')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("555-5555") === false);
|
testString: assert(telephoneCheck("555-5555") === false);
|
||||||
- text: <code>telephoneCheck("5555555")</code>应该返回false。
|
- text: "<code>telephoneCheck('5555555')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("5555555") === false);
|
testString: assert(telephoneCheck("5555555") === false);
|
||||||
- text: <code>telephoneCheck("1 555)555-5555")</code>应该返回false。
|
- text: "<code>telephoneCheck('1 555)555-5555')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("1 555)555-5555") === false);
|
testString: assert(telephoneCheck("1 555)555-5555") === false);
|
||||||
- text: <code>telephoneCheck("1 555 555 5555")</code>应该返回true。
|
- text: "<code>telephoneCheck('1 555 555 5555')</code>应该返回 true。"
|
||||||
testString: assert(telephoneCheck("1 555 555 5555") === true);
|
testString: assert(telephoneCheck("1 555 555 5555") === true);
|
||||||
- text: <code>telephoneCheck("1 456 789 4444")</code>应该返回true。
|
- text: "<code>telephoneCheck('1 456 789 4444')</code>应该返回 true。"
|
||||||
testString: assert(telephoneCheck("1 456 789 4444") === true);
|
testString: assert(telephoneCheck("1 456 789 4444") === true);
|
||||||
- text: '<code>telephoneCheck("123**&!!asdf#")</code>应该返回false。'
|
- text: "<code>telephoneCheck('123**&!!asdf#')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("123**&!!asdf#") === false);
|
testString: assert(telephoneCheck("123**&!!asdf#") === false);
|
||||||
- text: <code>telephoneCheck("55555555")</code>应该返回false。
|
- text: "<code>telephoneCheck('55555555')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("55555555") === false);
|
testString: assert(telephoneCheck("55555555") === false);
|
||||||
- text: <code>telephoneCheck("(6054756961)")</code>应该返回false
|
- text: "<code>telephoneCheck('(6054756961)')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("(6054756961)") === false);
|
testString: assert(telephoneCheck("(6054756961)") === false);
|
||||||
- text: <code>telephoneCheck("2 (757) 622-7382")</code>应该返回false。
|
- text: "<code>telephoneCheck('2 (757) 622-7382')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("2 (757) 622-7382") === false);
|
testString: assert(telephoneCheck("2 (757) 622-7382") === false);
|
||||||
- text: <code>telephoneCheck("0 (757) 622-7382")</code>应该返回false。
|
- text: "<code>telephoneCheck('0 (757) 622-7382')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("0 (757) 622-7382") === false);
|
testString: assert(telephoneCheck("0 (757) 622-7382") === false);
|
||||||
- text: <code>telephoneCheck("-1 (757) 622-7382")</code>应该返回false
|
- text: "<code>telephoneCheck('-1 (757) 622-7382')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("-1 (757) 622-7382") === false);
|
testString: assert(telephoneCheck("-1 (757) 622-7382") === false);
|
||||||
- text: <code>telephoneCheck("2 757 622-7382")</code>应该返回false。
|
- text: "<code>telephoneCheck('2 757 622-7382')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("2 757 622-7382") === false);
|
testString: assert(telephoneCheck("2 757 622-7382") === false);
|
||||||
- text: <code>telephoneCheck("10 (757) 622-7382")</code>应该返回false。
|
- text: "<code>telephoneCheck('10 (757) 622-7382')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("10 (757) 622-7382") === false);
|
testString: assert(telephoneCheck("10 (757) 622-7382") === false);
|
||||||
- text: <code>telephoneCheck("27576227382")</code>应该返回false。
|
- text: "<code>telephoneCheck('27576227382')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("27576227382") === false);
|
testString: assert(telephoneCheck("27576227382") === false);
|
||||||
- text: <code>telephoneCheck("(275)76227382")</code>应该返回false。
|
- text: "<code>telephoneCheck('(275)76227382')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("(275)76227382") === false);
|
testString: assert(telephoneCheck("(275)76227382") === false);
|
||||||
- text: <code>telephoneCheck("2(757)6227382")</code>应该返回false。
|
- text: "<code>telephoneCheck('2(757)6227382')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("2(757)6227382") === false);
|
testString: assert(telephoneCheck("2(757)6227382") === false);
|
||||||
- text: <code>telephoneCheck("2(757)622-7382")</code>应该返回false。
|
- text: "<code>telephoneCheck('2(757)622-7382')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("2(757)622-7382") === false);
|
testString: assert(telephoneCheck("2(757)622-7382") === false);
|
||||||
- text: <code>telephoneCheck("555)-555-5555")</code>应该返回false。
|
- text: "<code>telephoneCheck('555)-555-5555')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("555)-555-5555") === false);
|
testString: assert(telephoneCheck("555)-555-5555") === false);
|
||||||
- text: <code>telephoneCheck("(555-555-5555")</code>应该返回false。
|
- text: "<code>telephoneCheck('(555-555-5555')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("(555-555-5555") === false);
|
testString: assert(telephoneCheck("(555-555-5555") === false);
|
||||||
- text: <code>telephoneCheck("(555)5(55?)-5555")</code>应该返回false。
|
- text: "<code>telephoneCheck('(555)5(55?)-5555')</code>应该返回 false。"
|
||||||
testString: assert(telephoneCheck("(555)5(55?)-5555") === false);
|
testString: assert(telephoneCheck("(555)5(55?)-5555") === false);
|
||||||
|
|
||||||
```
|
```
|
||||||
@ -90,7 +96,6 @@ function telephoneCheck(str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
telephoneCheck("555-555-5555");
|
telephoneCheck("555-555-5555");
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -102,8 +107,15 @@ telephoneCheck("555-555-5555");
|
|||||||
## Solution
|
## Solution
|
||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// solution required
|
var re = /^([+]?1[\s]?)?((?:[(](?:[2-9]1[02-9]|[2-9][02-8][0-9])[)][\s]?)|(?:(?:[2-9]1[02-9]|[2-9][02-8][0-9])[\s.-]?)){1}([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2}[\s.-]?){1}([0-9]{4}){1}$/;
|
||||||
|
|
||||||
|
function telephoneCheck(str) {
|
||||||
|
return re.test(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
telephoneCheck("555-555-5555");
|
||||||
```
|
```
|
||||||
|
|
||||||
/section>
|
</section>
|
||||||
|
Reference in New Issue
Block a user