fix(challenges): I problems

This commit is contained in:
Kris Koishigawa
2019-03-06 14:18:18 +09:00
committed by mrugesh
parent a3fd1aa284
commit 263d2c496b
4 changed files with 41 additions and 36 deletions

View File

@ -6,16 +6,22 @@ challengeType: 5
## Description
<section id='description'>
The phrase <a href="https://en.wikipedia.org/wiki/I before E except after C"> "I before E, except after C"</a> is a widely known mnemonic which is supposed to help when spelling English words.
The phrase <a href="https://en.wikipedia.org/wiki/I before E except after C" target="_blank"> "I before E, except after C"</a> is a widely known mnemonic which is supposed to help when spelling English words.
Using the words provided, check if the two sub-clauses of the phrase are plausible individually:
<ol><li style='margin-bottom: 5px;'><i>"I before E when not preceded by C".</i></li><li><i>"E before I when preceded by C".</i></li></ol>
<ol>
<li>
<i>"I before E when not preceded by C".</i>
</li>
<li>
<i>"E before I when preceded by C".</i>
</li>
</ol>
If both sub-phrases are plausible then the original phrase can be said to be plausible.
Write a function that accepts a word and check if the word follows this rule. The function should return true if it follows the rule otherwise false.
</section>
## Instructions
<section id='instructions'>
Write a function that accepts a word and check if the word follows this rule. The function should return true if the word follows the rule and false if it does not.
</section>
## Tests
@ -50,7 +56,7 @@ tests:
<div id='js-seed'>
```js
function IBeforeExceptC (word) {
function IBeforeExceptC(word) {
// Good luck!
}
```
@ -66,7 +72,7 @@ function IBeforeExceptC (word) {
```js
function IBeforeExceptC (word)
function IBeforeExceptC(word)
{
if(word.indexOf("c")==-1 && word.indexOf("ie")!=-1)
return true;

View File

@ -6,20 +6,19 @@ challengeType: 5
## Description
<section id='description'>
The <a href="https://en.wikipedia.org/wiki/International_Bank_Account_Number">International Bank Account Number (IBAN)</a> is an internationally agreed means of identifying bank accounts across national borders with a reduced risk of propagating <a href="https://en.wikipedia.org/wiki/Transcription_error">transcription errors</a>.
The <a href="https://en.wikipedia.org/wiki/International_Bank_Account_Number" target="_blank">International Bank Account Number (IBAN)</a> is an internationally agreed means of identifying bank accounts across national borders with a reduced risk of propagating <a href="https://en.wikipedia.org/wiki/Transcription_error" target="_blank">transcription errors</a>.
The IBAN consists of up to 34 alphanumeric characters:
<ul>
<li>first the two-letter ISO 3166-1 alpha-2 country code</li>
<li>then two check digits, and</li>
<li>finally a country-specific Basic Bank Account Number (BBAN).</li>
<li>first the two-letter ISO 3166-1 alpha-2 country code</li>
<li>then two check digits, and</li>
<li>finally a country-specific Basic Bank Account Number (BBAN).</li>
</ul>
The check digits enable a sanity check of the bank account number to confirm its integrity even before submitting a transaction.
Write a function that takes IBAN string as parameter. If it is valid return true. Otherwise, return false.
</section>
## Instructions
<section id='instructions'>
Write a function that takes IBAN string as parameter. If it is valid return true. Otherwise, return false.
</section>
## Tests
@ -52,7 +51,7 @@ tests:
<div id='js-seed'>
```js
function isValid (iban) {
function isValid(iban) {
// Good luck!
}
```
@ -66,7 +65,7 @@ function isValid (iban) {
```js
function isValid (iban) {
function isValid(iban) {
var ibanLen = {
NO:15, BE:16, DK:18, FI:18, FO:18, GL:18, NL:18, MK:19,
SI:19, AT:20, BA:20, EE:20, KZ:20, LT:20, LU:20, CR:21,

View File

@ -6,16 +6,15 @@ challengeType: 5
## Description
<section id='description'>
An <i>identity matrix</i> is a square matrix of size \( n \times n \),
where the diagonal elements are all <b>1</b>s (ones),
and all the other elements are all <b>0</b>s (zeroes).
\begin{bmatrix} 1 & 0 & 0 \cr 0 & 1 & 0 \cr 0 & 0 & 1 \cr \end{bmatrix}
Write a function that takes a number 'n' as a parameter and returns the identity matrix of order n x n.
An <i>identity matrix</i> is a square matrix of size \( n \times n \), where the diagonal elements are all <b>1</b>s (ones), and all the other elements are all <b>0</b>s (zeroes).
<ul>
<li style="list-style: none;">\(\displaystyle I_{n}=\begin{bmatrix} 1 & 0 & 0 \cr 0 & 1 & 0 \cr 0 & 0 & 1 \cr \end{bmatrix}\)</li>
</ul>
</section>
## Instructions
<section id='instructions'>
Write a function that takes a number <code>n</code> as a parameter and returns the identity matrix of order \( n \times n \).
</section>
## Tests
@ -27,14 +26,14 @@ tests:
testString: assert(typeof idMatrix=='function','<code>idMatrix</code> should be a function.');
- text: <code>idMatrix(1)</code> should return an array.
testString: assert(Array.isArray(idMatrix(1)),'<code>idMatrix(1)</code> should return an array.');
- text: <code>idMatrix(1)</code> should return <code>'+JSON.stringify(results[0])+'</code>.
testString: assert.deepEqual(idMatrix(1),results[0],'<code>idMatrix(1)</code> should return <code>'+JSON.stringify(results[0])+'</code>.');
- text: <code>idMatrix(2)</code> should return <code>'+JSON.stringify(results[1])+'</code>.
testString: assert.deepEqual(idMatrix(2),results[1],'<code>idMatrix(2)</code> should return <code>'+JSON.stringify(results[1])+'</code>.');
- text: <code>idMatrix(3)</code> should return <code>'+JSON.stringify(results[2])+'</code>.
testString: assert.deepEqual(idMatrix(3),results[2],'<code>idMatrix(3)</code> should return <code>'+JSON.stringify(results[2])+'</code>.');
- text: <code>idMatrix(4)</code> should return <code>'+JSON.stringify(results[3])+'</code>.
testString: assert.deepEqual(idMatrix(4),results[3],'<code>idMatrix(4)</code> should return <code>'+JSON.stringify(results[3])+'</code>.');
- text: <code>idMatrix(1)</code> should return <code>[ [ 1 ] ]</code>.
testString: assert.deepEqual(idMatrix(1),results[0]);
- text: <code>idMatrix(2)</code> should return <code>[ [ 1, 0 ], [ 0, 1 ] ]</code>.
testString: assert.deepEqual(idMatrix(2),results[1]);
- text: <code>idMatrix(3)</code> should return <code>[ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1 ] ]</code>.
testString: assert.deepEqual(idMatrix(3),results[2]);
- text: <code>idMatrix(4)</code> should return <code>[ [ 1, 0, 0, 0 ], [ 0, 1, 0, 0 ], [ 0, 0, 1, 0 ], [ 0, 0, 0, 1 ] ]</code>.
testString: assert.deepEqual(idMatrix(4),results[3]);
```
@ -46,7 +45,7 @@ tests:
<div id='js-seed'>
```js
function idMatrix (n) {
function idMatrix(n) {
// Good luck!
}
```
@ -73,7 +72,7 @@ let results=[[ [ 1 ] ],
```js
function idMatrix (n) {
function idMatrix(n) {
return Array.apply(null, new Array(n)).map(function (x, i, xs) {
return xs.map(function (_, k) {
return i === k ? 1 : 0;

View File

@ -7,14 +7,15 @@ challengeType: 5
## Description
<section id='description'>
If you add the square of the digits of a Natural number (an integer bigger than zero), you always end with either 1 or 89:
<pre>15 -> 26 -> 40 -> 16 -> 37 -> 58 -> 89
7 -> 49 -> 97 -> 130 -> 10 -> 1</pre>
Write a function that takes a number as a parameter and returns 1 or 89 after performing the mentioned process.
<pre>
15 -> 26 -> 40 -> 16 -> 37 -> 58 -> 89
7 -> 49 -> 97 -> 130 -> 10 -> 1
</pre>
</section>
## Instructions
<section id='instructions'>
Write a function that takes a number as a parameter and returns 1 or 89 after performing the mentioned process.
</section>
## Tests
@ -49,7 +50,7 @@ tests:
<div id='js-seed'>
```js
function iteratedSquare (n) {
function iteratedSquare(n) {
// Good luck!
}
```
@ -65,7 +66,7 @@ function iteratedSquare (n) {
```js
function iteratedSquare (n) {
function iteratedSquare(n) {
var total;
while (n != 89 && n != 1) {
total = 0;