fix(curriculum): tests passing with seed code in Music player (#55586)

Co-authored-by: Sem Bauke <sem@freecodecamp.org>
pull/55940/head
Krzysztof G. 2024-08-26 12:58:43 +02:00 committed by GitHub
parent 6a24f8a744
commit 214f506e4c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 7 deletions

View File

@ -30,19 +30,19 @@ assert.match(code, /const\s+shuffle\s*=\s*\(\s*\)\s*=>\s*{\s*[\s\S]*?\}\s*;?/);
You should use the `sort()` method on `userData?.songs`.
```js
assert.match(code, /userData\?\.songs\.sort\(/)
assert.match(code, /const\s+shuffle\s*=\s*\(\s*\)\s*=>\s*{\s*userData\?\.songs\.sort\(/);
```
Your `sort()` method should have a callback function that uses arrow syntax.
```js
assert.match(code, /userData\?\.songs\.sort\(\s*\(\s*\)\s*=>\s*/)
assert.match(code, /const\s+shuffle\s*=\s*\(\s*\)\s*=>\s*{\s*userData\?\.songs\.sort\(\s*\(\s*\)\s*=>\s*/);
```
The callback of your `sort()` method should return `Math.random() - 0.5`.
```js
assert.match(code, /userData\?\.songs\.sort\s*\(\s*\(\s*\)\s*=>(\s*{\s*return\s+Math\.random\(\s*\)\s*-\s*0\.5\s*;?\s*}\s*)|(\s*Math\.random\(\s*\)\s*-\s*0\.5\s*)\s*\)\s*;?/);
assert.match(code, /const\s+shuffle\s*=\s*\(\s*\)\s*=>\s*{\s*userData\?\.songs\.sort\s*\(\s*\(\s*\)\s*=>(\s*{\s*return\s+Math\.random\(\s*\)\s*-\s*0\.5\s*;?\s*}\s*)|(\s*Math\.random\(\s*\)\s*-\s*0\.5\s*)\s*\)\s*;?/);
```
# --seed--

View File

@ -33,10 +33,11 @@ Inside your callback function, add another `if` statement to check if `a.title`
# --hints--
You should have an `if` statement inside your callback function.
You should have a second `if` statement inside your callback function.
```js
assert.match(code, /if\s*\(/);
const callback = code.split(/const\s+sortSongs\s*=\s*\(\s*\)\s*=>\s*\{/)?.[1]?.split(/\}\s*\)\s*;?\s*\}/)?.[0];
assert.lengthOf(callback?.match(/if\s*\(/g), 2);
```
Your `if` statement should check if `a.title` is greater than `b.title`.

View File

@ -22,7 +22,7 @@ assert.isFunction(sortSongs);
Your `sortSongs` function should use arrow function syntax.
```js
assert.match(code, /const|let\s+sortSongs\s*=\s*\(\s*\)\s*=>\s*{\s*}\s*;?/)
assert.match(code, /(const|let)\s+sortSongs\s*=\s*\(\s*\)\s*=>\s*{\s*}\s*;?/)
```
# --seed--

View File

@ -16,7 +16,7 @@ Start by removing the `printGreeting`, `printMessage`, and `addTwoNumbers` funct
You should not have a `printGreeting` function.
```js
assert.notMatch(code, /const printGreeting = () => {/);
assert.notMatch(code, /const printGreeting = \(\) => {/);
```
You should not have a `printMessage` function.