fix(curriculum): fixes pyramid range error (#55486)

This commit is contained in:
Patrick Wauschek
2024-07-25 02:22:04 -05:00
committed by GitHub
parent 73f00af79e
commit da7719f22d
2 changed files with 7 additions and 17 deletions
@@ -11,14 +11,16 @@ Using `done` to track the number of rows that have been generated is functional,
Arrays have a special `length` property that allows you to see how many values, or <dfn>elements</dfn>, are in the array. You would access this property using syntax like `myArray.length`.
Update your condition to check if `rows.length` is less than or equal to `count`.
Note that `rows.length` in the `padRow` call would give you an off-by-one error, because `done` is incremented *before* the call.
Update your condition to check if `rows.length` is less than `count`.
# --hints--
Your `while` loop should check if `rows.length` is less than or equal to `count`.
Your `while` loop should check if `rows.length` is less than `count`.
```js
assert.match(__helpers.removeJSComments(code), /while\s*\(\s*rows\.length\s*<=\s*count\s*\)/);
assert.match(__helpers.removeJSComments(code), /while\s*\(\s*rows\.length\s*<\s*count\s*\)/);
```
# --seed--
@@ -7,13 +7,7 @@ dashedName: step-96
# --description--
You can also replace the `done` reference in your `padRow` call.
Note that `rows.length` here would give you an off-by-one error, because `done` is incremented *before* the call.
So you'll need to replace `done` here with `rows.length + 1`. When you do this, you may see a `Range Error`, because we've created another off-by-one error.
You'll need to change the `while` condition to use the less than operator, instead of the less than or equal operator.
Replace the `done` reference in your `padRow` call with `rows.length + 1`.
# --hints--
@@ -23,12 +17,6 @@ You should pass `rows.length + 1` as the first argument to your `padRow` call.
assert.match(__helpers.removeJSComments(code), /rows\.push\(padRow\s*\(\s*rows\.length\s*\+\s*1/);
```
Your `while` loop should run while `rows.length` is less than `count`.
```js
assert.match(__helpers.removeJSComments(code), /while\s*\(\s*rows\.length\s*<\s*count\)/);
```
# --seed--
## --seed-contents--
@@ -50,7 +38,7 @@ function padRow(rowNumber, rowCount) {
--fcc-editable-region--
let done = 0;
while (rows.length <= count) {
while (rows.length < count) {
done++;
rows.push(padRow(done, count));
}