fix(curriculum): test for values step 25 spreadsheet instructions (#57477)

Co-authored-by: Naomi <accounts+github@nhcarrigan.com>
This commit is contained in:
Anna 2024-12-14 07:47:04 -05:00 committed by GitHub
parent e5a5f3fd7d
commit 40b3b1ae77
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,62 +7,29 @@ dashedName: step-25
# --description--
Using ternary syntax, check if `length` is even using your `isEven` function. If it is, return the average of the number at the `middle` index and the number after that. If it's odd, return the number at the `middle` index you'll need to round the `middle` value up.
Check if `length` is even using your `isEven` function. If it is, return the average of the number at the `middle` index and the number after that. If it's odd, return the number at the `middle` index you'll need to round the `middle` value up.
# --hints--
You should use the `return` keyword.
You should return a value from the `median` function.
```js
assert.match(code, /const\s+median\s*=\s*nums\s*=>\s*\{\s*const\s+sorted\s*=\s*nums\.slice\(\s*\)\.sort\(\s*\(\s*a\s*,\s*b\s*\)\s*=>\s*a\s*-\s*b\s*\)\s*\s*;?\s*const\s+length\s*=\s*sorted\.length\s*;?\s*const\s+middle\s*=\s*length\s*\/\s*2\s*-\s*1\s*;?\s*return/);
assert.exists(median([2,4,6,8]));
```
You should call your `isEven()` function after your `return` keyword.
If `length` is even, you should return the average of the number at the `middle` index and the number after it.
```js
assert.match(code, /const\s+median\s*=\s*nums\s*=>\s*\{\s*const\s+sorted\s*=\s*nums\.slice\(\s*\)\.sort\(\s*\(\s*a\s*,\s*b\s*\)\s*=>\s*a\s*-\s*b\s*\)\s*\s*;?\s*const\s+length\s*=\s*sorted\.length\s*;?\s*const\s+middle\s*=\s*length\s*\/\s*2\s*-\s*1\s*;?\s*return\s+isEven\(/);
assert.strictEqual(median([2,4,6,8]),5);
assert.strictEqual(median([6,12,18,24]),15);
```
You should pass your `length` variable to your `isEven()` call.
If `length` is odd, you should return the value at the `middle` index.
```js
assert.match(code, /const\s+median\s*=\s*nums\s*=>\s*\{\s*const\s+sorted\s*=\s*nums\.slice\(\s*\)\.sort\(\s*\(\s*a\s*,\s*b\s*\)\s*=>\s*a\s*-\s*b\s*\)\s*\s*;?\s*const\s+length\s*=\s*sorted\.length\s*;?\s*const\s+middle\s*=\s*length\s*\/\s*2\s*-\s*1\s*;?\s*return\s+isEven\(\s*length\s*\)/);
```
You should use ternary syntax to check the truthiness of your `isEven()` call.
```js
assert.match(code, /const\s+median\s*=\s*nums\s*=>\s*\{\s*const\s+sorted\s*=\s*nums\.slice\(\s*\)\.sort\(\s*\(\s*a\s*,\s*b\s*\)\s*=>\s*a\s*-\s*b\s*\)\s*\s*;?\s*const\s+length\s*=\s*sorted\.length\s*;?\s*const\s+middle\s*=\s*length\s*\/\s*2\s*-\s*1\s*;?\s*return\s+isEven\(\s*length\s*\)\s*\?/);
```
If the ternary is truthy, you should call your `average()` function.
```js
assert.match(code, /const\s+median\s*=\s*nums\s*=>\s*\{\s*const\s+sorted\s*=\s*nums\.slice\(\s*\)\.sort\(\s*\(\s*a\s*,\s*b\s*\)\s*=>\s*a\s*-\s*b\s*\)\s*\s*;?\s*const\s+length\s*=\s*sorted\.length\s*;?\s*const\s+middle\s*=\s*length\s*\/\s*2\s*-\s*1\s*;?\s*return\s+isEven\(\s*length\s*\)\s*\?\s*average\(/);
```
You should pass an array to your `average()` function.
```js
assert.match(code, /const\s+median\s*=\s*nums\s*=>\s*\{\s*const\s+sorted\s*=\s*nums\.slice\(\s*\)\.sort\(\s*\(\s*a\s*,\s*b\s*\)\s*=>\s*a\s*-\s*b\s*\)\s*\s*;?\s*const\s+length\s*=\s*sorted\.length\s*;?\s*const\s+middle\s*=\s*length\s*\/\s*2\s*-\s*1\s*;?\s*return\s+isEven\(\s*length\s*\)\s*\?\s*average\(\s*\[/);
```
The first element of the array passed to `average()` should be the element at the `middle` index of your `sorted` array.
```js
assert.match(code, /const\s+median\s*=\s*nums\s*=>\s*\{\s*const\s+sorted\s*=\s*nums\.slice\(\s*\)\.sort\(\s*\(\s*a\s*,\s*b\s*\)\s*=>\s*a\s*-\s*b\s*\)\s*\s*;?\s*const\s+length\s*=\s*sorted\.length\s*;?\s*const\s+middle\s*=\s*length\s*\/\s*2\s*-\s*1\s*;?\s*return\s+isEven\(\s*length\s*\)\s*\?\s*average\(\s*\[\s*sorted\s*\[\s*middle\s*\]/);
```
The first element of the array passed to `average()` should be the element at the `middle + 1` index of your `sorted` array.
```js
assert.match(code, /const\s+median\s*=\s*nums\s*=>\s*\{\s*const\s+sorted\s*=\s*nums\.slice\(\s*\)\.sort\(\s*\(\s*a\s*,\s*b\s*\)\s*=>\s*a\s*-\s*b\s*\)\s*\s*;?\s*const\s+length\s*=\s*sorted\.length\s*;?\s*const\s+middle\s*=\s*length\s*\/\s*2\s*-\s*1\s*;?\s*return\s+isEven\(\s*length\s*\)\s*\?\s*average\(\s*\[\s*sorted\s*\[\s*middle\s*\]\s*,\s*sorted\s*\[\s*middle\s*\+\s*1\s*\]\s*\]\s*\)/);
```
If the ternary is false, you should return the value of `sorted` at the `middle` index. Use `Math.ceil()` to round the `middle` value up.
```js
assert.match(code, /const\s+median\s*=\s*nums\s*=>\s*\{\s*const\s+sorted\s*=\s*nums\.slice\(\s*\)\.sort\(\s*\(\s*a\s*,\s*b\s*\)\s*=>\s*a\s*-\s*b\s*\)\s*\s*;?\s*const\s+length\s*=\s*sorted\.length\s*;?\s*const\s+middle\s*=\s*length\s*\/\s*2\s*-\s*1\s*;?\s*return\s+isEven\(\s*length\s*\)\s*\?\s*average\(\s*\[\s*sorted\s*\[\s*middle\s*\]\s*,\s*sorted\s*\[\s*middle\s*\+\s*1\s*\]\s*\]\s*\)\s*:\s*sorted\s*\[\s*Math\.ceil\(\s*middle\s*\)\s*\]\s*;?/);
assert.strictEqual(median([2,4,6,8,10]),6);
assert.strictEqual(median([3,6,9,12,15]),9);
```
# --seed--