Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main(authors) {
- authors.forEach(function(author) {
- let name, articles;
- if (author) {
- if (author.name) {
- name = author.name;
- } else if (author.firstName) {
- if (author.lastName) {
- name = author.firstName + ' ' + author.lastName;
- } else {
- name = author.firstName;
- }
- }
- }
- if (!name) {
- name = '<Unknown author>';
- }
- if (author) {
- articles = author.articles;
- }
- if (!articles) {
- articles = [];
- }
- let articleCount = articles.length;
- let maybeS = articleCount > 1 || articleCount === 0 ? 's' : '';
- console.log(`${name} has published ${articles.length} article${maybeS}.`);
- articles.forEach(function(article) {
- let title, wordCount;
- if (article) {
- title = article.title;
- }
- if (!title) {
- title = '<Untitled>';
- }
- if (article) {
- if (article.contents) {
- let words = article.contents
- .split(/[^A-Za-z']+/)
- .filter(word => !!word);
- wordCount = words.length;
- }
- }
- if (!wordCount) {
- wordCount = 0;
- }
- console.log(` Article ${title} has ${wordCount} words.`);
- });
- });
- }
Add Comment
Please, Sign In to add comment