NW5-Mamadou-Barry-JavaScript-Week3 - #134
Conversation
All compile and pass except the function "titleWithFewestWords"
MustafaAcar-sys
left a comment
There was a problem hiding this comment.
Hi, Barry, I could not check your code in detail but it seems you have done it. Congrats.
AltomHussain
left a comment
There was a problem hiding this comment.
Overall great job my friend keep trying :)
| // TODO | ||
| } | ||
| if (cities === []) { // TODO | ||
| return []; |
There was a problem hiding this comment.
You don't even need the check for empty array because it will return empty anyways if its passed as empty array
| let headlineOnNumber = []; | ||
| for (let i = 0; i < allArticleTitles.length; i++){// TODO | ||
| for (let loopOnElement of allArticleTitles[i]){ | ||
| if ( loopOnElement === "$"){ |
There was a problem hiding this comment.
There is anthor simpler way of checking if a string contains number, using rejex check this out:
let NewArr = [];
for (let index = 0; index < allArticleTitles.length; index++) {
if (/\d/.test(allArticleTitles[index]))
NewArr.push(allArticleTitles[index]);
}
return NewArr;
}```
In your case, you are checking `$` sign but that might change I mean you might have a number without `$` so .....
There was a problem hiding this comment.
yes you are right, I use the sign "$" because I ran out of options and need this code to compile. I know this is now what they asked.
I did not really understand this if (/\d/.test(allArticleTitles[index]))but I should have use the condition below.
if (loopOnElement >="0" or loopOnElement <="9") then push
All compile and pass except the function "titleWithFewestWords"