Fix example code on filter method to avoid confusion
This commit is contained in:
@ -322,10 +322,10 @@
|
|||||||
"The <code>filter</code> method is used to iterate through an array and filter out elements where a given condition is not true.",
|
"The <code>filter</code> method is used to iterate through an array and filter out elements where a given condition is not true.",
|
||||||
"<code>filter</code> is passed a callback function which takes the current value (we've called that <code>val</code>) as an argument.",
|
"<code>filter</code> is passed a callback function which takes the current value (we've called that <code>val</code>) as an argument.",
|
||||||
"Any array element for which the callback returns true will be kept and elements that return false will be filtered out.",
|
"Any array element for which the callback returns true will be kept and elements that return false will be filtered out.",
|
||||||
"The following code is an example of using filter to remove array elements that are not even numbers:",
|
"The following code is an example of using <code>filter</code> to remove array elements that are equal to five:",
|
||||||
"Note: We omit the second and third arguments since we only need the value",
|
"Note: We omit the second and third arguments since we only need the value",
|
||||||
"<code>array = array.filter(function(val) {</code>",
|
"<code>array = array.filter(function(val) {</code>",
|
||||||
"<code> return val % 2 === 0;</code>",
|
"<code> return val !== 5;</code>",
|
||||||
"<code>});</code>",
|
"<code>});</code>",
|
||||||
"Use <code>filter</code> to remove all elements from <code>array</code> that are greater than 5."
|
"Use <code>filter</code> to remove all elements from <code>array</code> that are greater than 5."
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user