Bug in Step 7 of "Learn Advanced Array Methods by Building a Statistics Calculator"

Hi FreeCodeCamp team,

I found a bug in Step 7 of the JavaScript Algorithms and Data Structures course under “Learn Advanced Array Methods by Building a Statistics Calculator.”

The test is incorrectly passing my solution even though my '' method contains a syntax error. My incorrect code:

const calculate = () => {
  const value = document.querySelector("#numbers").value;
  const array = value.split(/,\s*/g);
  const numbers = array.map(el => Number(el));
  const filtered = numbers.filter(el => {!isNaN(el)}); // Incorrect syntax
}

Issue:

The '' callback implicitly returns undefined because it uses ''` without a ‘’` statement. The correct syntax should be either:

(1) Using an implicit return (no'' needed):

javascript

CopyEdit

const filtered = numbers.filter(el => !isNaN(el));

(2) Using an explicit return (with '' and ''):

javascript

CopyEdit

const filtered = numbers.filter(el => {
  return !isNaN(el);
});

However, the test still passes even though my function does not return a proper filtered array.

Expected Behavior:

The test should fail when the'' function is incorrectly written with'' but no explicit ''.

Can you please review this and update the test conditions to ensure that incorrect implementations do not pass?

Thanks for your time and the great learning platform!

Best,
FIRAOL FEYISA

1 Like

Hey there :wave:

Can you provide a link to the exercise where your code is incorrectly passing?

I do not understand what this means

I do not understand what you are saying is the error, can you explain more?

Subject: Bug in Step 7 of JavaScript Algorithms and Data Structures Course

Hi FreeCodeCamp team,

I found an issue in Step 7 of the JavaScript Algorithms and Data Structures course under “Learn Advanced Array Methods by Building a Statistics Calculator.”

The test is incorrectly passing my solution even though my filter method contains a syntax error. Here’s my incorrect code:

javascript

CopyEdit

const calculate = () => {
  const value = document.querySelector("#numbers").value;
  const array = value.split(/,\s*/g);
  const numbers = array.map(el => Number(el));
  const filtered = numbers.filter(el => {!isNaN(el)}); // Incorrect syntax
}

Issue:

The callback function in the filter method implicitly returns undefined because it uses {} without a return statement. The correct syntax should be one of the following:

  1. Using implicit return (no curly braces needed):

javascript

CopyEdit

const filtered = numbers.filter(el => !isNaN(el));
  1. Using explicit return (with curly braces and return keyword):

javascript

CopyEdit

const filtered = numbers.filter(el => {
  return !isNaN(el);
});

However, despite the incorrect syntax, the test still passes.

Expected Behavior:

The test should fail when the filter method is incorrectly written with {} but without an explicit return.

Could you please review this and update the test conditions to ensure that incorrect implementations do not pass?

Thanks for your time and for providing such a great learning platform!

Best,
Firaol Feyisa

Subject: Bug in Step 7 of JavaScript Algorithms and Data Structures Course

Hi FreeCodeCamp team,

I found an issue in Step 7 of the JavaScript Algorithms and Data Structures course under “Learn Advanced Array Methods by Building a Statistics Calculator.”

The test is incorrectly passing my solution even though my filter method contains a syntax error. Here’s my incorrect code:

javascript

CopyEdit

const calculate = () => {
  const value = document.querySelector("#numbers").value;
  const array = value.split(/,\s*/g);
  const numbers = array.map(el => Number(el));
  const filtered = numbers.filter(el => {!isNaN(el)}); // Incorrect syntax
}

Issue:

The callback function in the filter method implicitly returns undefined because it uses {} without a return statement. The correct syntax should be one of the following:

  1. Using implicit return (no curly braces needed):

javascript

CopyEdit

const filtered = numbers.filter(el => !isNaN(el));
  1. Using explicit return (with curly braces and return keyword):

javascript

CopyEdit

const filtered = numbers.filter(el => {
  return !isNaN(el);
});

However, despite the incorrect syntax, the test still passes.

Expected Behavior:

The test should fail when the filter method is incorrectly written with {} but without an explicit return.

Could you please review this and update the test conditions to ensure that incorrect implementations do not pass?

Thanks for your time and for providing such a great learning platform!

Best,
Firaol Feyisa

Sorry, here is the corrected version of my request
Subject: Bug in Step 7 of JavaScript Algorithms and Data Structures Course

Hi FreeCodeCamp team,

I found an issue in Step 7 of the JavaScript Algorithms and Data Structures course under “Learn Advanced Array Methods by Building a Statistics Calculator.”

The test is incorrectly passing my solution even though my filter method contains a syntax error. Here’s my incorrect code:

javascript

CopyEdit

const calculate = () => {
  const value = document.querySelector("#numbers").value;
  const array = value.split(/,\s*/g);
  const numbers = array.map(el => Number(el));
  const filtered = numbers.filter(el => {!isNaN(el)}); // Incorrect syntax
}

Issue:

The callback function in the filter method implicitly returns undefined because it uses {} without a return statement. The correct syntax should be one of the following:

  1. Using implicit return (no curly braces needed):

javascript

CopyEdit

const filtered = numbers.filter(el => !isNaN(el));
  1. Using explicit return (with curly braces and return keyword):

javascript

CopyEdit

const filtered = numbers.filter(el => {
  return !isNaN(el);
});

However, despite the incorrect syntax, the test still passes.

Expected Behavior:

The test should fail when the filter method is incorrectly written with {} but without an explicit return.

Could you please review this and update the test conditions to ensure that incorrect implementations do not pass?

Thanks for your time and for providing such a great learning platform!

Best,
Firaol Feyisa

For everyone checking out this post, here is a corrected version of my question or request

Subject: Bug in Step 7 of JavaScript Algorithms and Data Structures Course

Hi FreeCodeCamp team,

I found an issue in Step 7 of the JavaScript Algorithms and Data Structures course under “Learn Advanced Array Methods by Building a Statistics Calculator.”

The test is incorrectly passing my solution even though my filter method contains a syntax error. Here’s my incorrect code:

javascript

CopyEdit

const calculate = () => {
  const value = document.querySelector("#numbers").value;
  const array = value.split(/,\s*/g);
  const numbers = array.map(el => Number(el));
  const filtered = numbers.filter(el => {!isNaN(el)}); // Incorrect syntax
}

Issue:

The callback function in the filter method implicitly returns undefined because it uses {} without a return statement. The correct syntax should be one of the following:

  1. Using implicit return (no curly braces needed):

javascript

CopyEdit

const filtered = numbers.filter(el => !isNaN(el));
  1. Using explicit return (with curly braces and return keyword):

javascript

CopyEdit

const filtered = numbers.filter(el => {
  return !isNaN(el);
});

However, despite the incorrect syntax, the test still passes.

Expected Behavior:

The test should fail when the filter method is incorrectly written with {} but without an explicit return.

Could you please review this and update the test conditions to ensure that incorrect implementations do not pass?

Thanks for your time and for providing such a great learning platform!

Best,
Firaol Feyisa

Ok,now I get it. That looks something that needs to go on a github issue, can you open one?

Cool, i have done that You can check it out here