-
-
Notifications
You must be signed in to change notification settings - Fork 279
London class-10- Junita Lama -Java script core 1- week 3 #236
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,13 @@ | |
| Implement the function below, which will return a new array containing only article titles which will fit. | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks perfect!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks, i will fix it . |
||
| function potentialHeadlines(allArticleTitles) { | ||
| // TODO | ||
| let titleCharacters = []; | ||
| for(let title of allArticleTitles) { | ||
| if(title.length <= 65) { | ||
| titleCharacters.push(title); | ||
| } | ||
| } | ||
| return titleCharacters; | ||
| } | ||
|
|
||
| /* | ||
|
|
@@ -14,24 +20,53 @@ function potentialHeadlines(allArticleTitles) { | |
| (you can assume words will always be seperated by a space) | ||
| */ | ||
| function titleWithFewestWords(allArticleTitles) { | ||
| // TODO | ||
| let shortestHeadline; | ||
| let fewestNumberOfWords; | ||
| for(let title of allArticleTitles){ | ||
| let numberOfWords = title.split(' ').length; | ||
| if (fewestNumberOfWords === undefined || numberOfWords < fewestNumberOfWords){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good job! you have used || in if function but I have used greater > in if function. |
||
| fewestNumberOfWords=numberOfWords; | ||
| shortestHeadline = title; | ||
| } | ||
| } | ||
| return shortestHeadline; | ||
| } | ||
|
|
||
|
|
||
| /* | ||
| The editor of the FT has realised that headlines which have numbers in them get more clicks! | ||
| Implement the function below to return a new array containing all the headlines which contain a number. | ||
| (Hint: remember that you can also loop through the characters of a string if you need to) | ||
| */ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks good 👍 |
||
| function containsNumbers(str) { | ||
| return /[0-9]/.test(str); | ||
| } | ||
|
|
||
| function headlinesWithNumbers(allArticleTitles) { | ||
| // TODO | ||
| let titlesWithNumbers = []; | ||
|
|
||
| for(let title of allArticleTitles){ | ||
| if (containsNumbers(title)== true) { | ||
| titlesWithNumbers.push(title); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| return titlesWithNumbers; | ||
| } | ||
|
|
||
| /* | ||
| The Financial Times wants to understand what the average number of characters in an article title is. | ||
| Implement the function below to return this number - rounded to the nearest integer. | ||
| */ | ||
| function averageNumberOfCharacters(allArticleTitles) { | ||
| // TODO | ||
| let countAllWords = 0; | ||
| let noOfArticles = allArticleTitles.length; | ||
| for(let title of allArticleTitles){ | ||
| countAllWords = countAllWords + title.length; | ||
| } | ||
| let averageWords = Math.round(countAllWords/noOfArticles); | ||
| return averageWords; | ||
| } | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one 👍