![krystynas799](/avatars/3233.jpg)
krystynas799
08.12.2020 •
Computers and Technology
Write a function named countWords that reads in a line of text into a string variable, counts and returns the number of words in the line. For simplicity assume that the line entered only has characters and spaces.
Solved
Show answers
More tips
- H Health and Medicine 10 Ways to Cleanse Your Colon and Improve Your Health...
- W Work and Career How to Write a Resume That Catches the Employer s Attention?...
- C Computers and Internet Е-head: How it Simplifies Life for Users?...
- F Family and Home How to Choose the Best Diapers for Your Baby?...
- F Family and Home Parquet or laminate, which is better?...
- L Leisure and Entertainment How to Properly Wind Fishing Line onto a Reel?...
- L Leisure and Entertainment How to Make a Paper Boat in Simple Steps...
- T Travel and tourism Maldives Adventures: What is the Best Season to Visit the Luxurious Beaches?...
- H Health and Medicine Kinesiology: What is it and How Does it Work?...
- O Other How to Choose the Best Answer to Your Question on The Grand Question ?...
Answers on questions: Computers and Technology
- C Computers and Technology When you check to see how much RAM, or temporary storage you have available, you are checking your . primary memory secondary storage secondary memory tertiary storage...
- B Business U.S. Treasury STRIPS, close of business November 15, 2015: Maturity Price Maturity Price November ’16 99.471 November ’19 95.035 November ’17 98.782 November ’20 92.570...
- C Computers and Technology 1. Draw the stack frame as seen at the end of the following fragment of a code. Detail the contents of the stack: a. Assume that the initial value in SP was 0x7EFFF290;...
- B Business Sandia corporation is considering two independent projects. For our purposes, we will call them projects A and B. Project A is expected to cost $39,265, and project B...
- P Physics Certain neutron stars (extremely dense stars) are believed to be rotating at about 0.83 rev/s. If such a star has a radius of 40 km, what must be its minimum mass so...
- M Mathematics How can I rationalize the denominator...
- M Mathematics Find the GCF of 24m and 16mn....
- M Mathematics At what speed in meters per minute are passengers on the wheel traveling? . A ride on The London Eye, one complete revolution takes 30 minutes passengers step on the...
- M Mathematics Thecube of twice a number...
- M Mathematics Apply the distributive property to create An...
Ответ:
function countWords(sentence) {
return sentence.match(/\S+/g).length;
}
const sentence = 'This sentence has five words ';
console.log(`"${sentence}" has ${countWords(sentence)} words` );
Explanation:
Regular expressions are a powerful way to tackle this. One obvious cornercase is that multiple spaces could occur. The regex doesn't care.
Ответ:
SPONGEBOB SQUARE PANTS