mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-06-19 21:09:51 +08:00
Fix: add note to explain number is not checked (#53155)
Co-authored-by: Jessica Wilkins <67210629+jdwilkin4@users.noreply.github.com> Co-authored-by: Bruce Blaser <bbsmooth@gmail.com>
This commit is contained in:
parent
7fc7fb711e
commit
ad57bfd365
@ -11,7 +11,7 @@ Now that you have the value of the input, you need to split it into an array of
|
||||
|
||||
The `.split()` method takes a string and splits it into an array of strings. You can pass it a string of characters or a RegEx to use as a separator. For example, `string.split(",")` would split the string at each comma and return an array of strings.
|
||||
|
||||
Use a regex to split the `value` string by commas followed by any number of spaces. Store the array in an `array` variable.
|
||||
Use the `/,\s*/g` regex to split the `value` string by commas. You can tweak it based on the number of spaces seperating your values. Store the array in an `array` variable.
|
||||
|
||||
# --hints--
|
||||
|
||||
@ -33,6 +33,12 @@ Your `calculate` function should assign the result of the `.split()` method to t
|
||||
assert.match(code.toString(), /array\s*=\s*value\.split()/);
|
||||
```
|
||||
|
||||
You should use `/,\s*/g` for the `split()` method's separator.
|
||||
|
||||
```js
|
||||
assert.match(code.toString(), /value\.split\(\s*\/,\s*\\s*\*\s*\/g\)/);
|
||||
```
|
||||
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
@ -17,7 +17,7 @@ array.filter(el => {
|
||||
|
||||
The callback function needs to return a Boolean value, which indicates whether the element should be included in the new array. In this case, you want to return `true` if the element is not `NaN` (not a number).
|
||||
|
||||
However, you cannot check for equality here, because `NaN` is not equal to itself. Instead, you can use the `Number.isNaN()` method, which returns `true` if the argument is `NaN`.
|
||||
However, you cannot check for equality here, because `NaN` is not equal to itself. Instead, you can use the `isNaN()` method, which returns `true` if the argument is `NaN`.
|
||||
|
||||
Add a callback function to your `.filter()` method that returns `true` if the element is not `NaN`.
|
||||
|
||||
@ -29,10 +29,10 @@ Your `.filter()` method should have a callback which accepts `el` as a parameter
|
||||
assert.match(calculate.toString(), /numbers\.filter\(\(?\s*el\s*\)?\s*=>|numbers\.filter\(function\s*\(?el\)\s*\{/)
|
||||
```
|
||||
|
||||
Your callback function should use `!` and `Number.isNaN()` to check if `el` is NOT `NaN`.
|
||||
Your callback function should use `!` and `isNaN()` to check if `el` is NOT `NaN`.
|
||||
|
||||
```js
|
||||
assert.match(calculate.toString(), /!(Number\.)?isNaN\(\s*el\s*\)/);
|
||||
assert.match(calculate.toString(), /!\s*(Number\.)?isNaN\(\s*el\s*\)/);
|
||||
```
|
||||
|
||||
Your callback function should return elements that are not `NaN`.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user