fix(curriculum): log test, method return, example code (#55298)

This commit is contained in:
Lasse Jørgensen 2024-06-24 11:07:46 +02:00 committed by GitHub
parent be79c94de5
commit c70b4beb8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 7 deletions

View File

@ -7,15 +7,15 @@ dashedName: step-107
# --description--
The `.unshift()` method of an array allows you to add a value to the **beginning** of the array, unlike `.push()` which adds the value at the end of the array. Here is an example:
The `.unshift()` method of an array allows you to add a value to the **beginning** of the array, unlike `.push()` which adds the value at the end of the array. `.unshift()` returns the new length of the array it was called on.
```js
const numbers = [1, 2, 3];
numbers.unshift(5);
const countDown = [2, 1, 0];
const newLength = countDown.unshift(3);
console.log(countDown); // [3, 2, 1, 0]
console.log(newLength); // 4
```
The `numbers` array would now be `[5, 1, 2, 3]`.
Use `const` to declare an `unshifted` variable, and assign it the result of calling `.unshift()` on your `numbers` array. Pass `5` as the argument. Then print your `unshifted` variable.
# --hints--
@ -44,6 +44,12 @@ You should assign the result of your `.unshift()` call to your `unshifted` varia
assert.equal(unshifted, 4);
```
You should log your `unshifted` variable.
```js
assert.match(__helpers.removeJSComments(code), /console\.log\(\s*unshifted\s*\);?/);
```
# --seed--
## --seed-contents--

View File

@ -7,8 +7,6 @@ dashedName: step-108
# --description--
Notice that like `.push()`, `.unshift()` returns the new length of the array after the element is added.
Arrays also have a `.shift()` method. This will remove the **first** element of the array, unlike `.pop()` which removes the last element. Here is an example of the `.shift()` method:
```js