1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
maksim [4K]
3 years ago
11

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.
Computers and Technology
1 answer:
algol133 years ago
3 0

Answer:

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.

You might be interested in
What are the home row keys?
kramer
ASDF JKL; are the home row keys.
7 0
3 years ago
In mathematics, "quadrant I" of the cartesian plane is the part of the plane where x and y are both positive. Given a variable,
lbvjy [14]

Answer:

#include <iostream>

using namespace std;

struct Cartesian {

double x;

double y;

};

int main() {

// creating a pointer p of type struct Cartesian

struct Cartesian *p = new Cartesian ;

cout << " Enter x: ";

// accessing the structure variable x by arrow "->"

cin >> p->x;

cout << "Enter y: ";

// accessing the structure variable y by arrow "->"

cin >> p->y;

// expression to check whether x and y lie in Quadrant 1

if (p->x > 0 && p->y > 0) {

 cout << "X and Y are in Quadrant 1 ";

}

else

{

 cout << "x And y are not in Quadrant 1";

}

// deleting the struct pointer p

delete p;

return 0;

}

Explanation:

in order to locate memory in heap, keyword "new" is used in C++ so,

struct Cartesian *p = new Cartesian ;

in order to access data members of the structure using pointer we always use an arrow "->". otherwise a dot oprerator is used to access data members.

in order to check whether x and y lie in 1st quadrent, we must use && operator in our if condition. so

if (p->x > 0 && p->y > 0)

&& will return true iff x and y both are +ve.

deleting the struct pointer p is important beacuse we are allocating memory in heap so heap memory should be used a resource and must be release when not needed otherwise it can cause memory leakage problems. so  

delete p;

5 0
3 years ago
Media applications that play audio or video files are part of a class of workkloads called "streaming" workloads (i.e., they bri
emmasim [6.3K]

Answer:

Following is the detailed answer as needed.

<h3>I hope it will help you!</h3>

Explanation:

8 0
3 years ago
State whether True / False:<br>The pause option stops the recording temporarily.*<br>True<br>False​
defon

Answer:

true

Explanation:

when you pause a recording it will temporarily stop but, when you hit record again it will continue where you left off

7 0
3 years ago
____ are diagrams used in mathematics and logic to help describe the truth of an entire expression based on the truth of its par
Bad White [126]
<span>Truth tables are diagrams used in mathematics and logic to help describe the truth of an entire expression based on the truth of its parts.

A truth table shows all the possible combinations (outputs) that can be produced from the given inputs. They are mainly used in Boolean algebra.</span>
4 0
3 years ago
Other questions:
  • Have you ever used a device that relies solely on the cloud?
    10·1 answer
  • This is the thing that I don't understand why did they banned private chat like there are long-distance relationships, and frien
    13·2 answers
  • What are computer virus ? Explain in detail.In your answer include symptoms and prevention (3each)
    10·1 answer
  • Your team will write a function that reverses a C-string, to practice using pointers. You must use pointers and C-strings for th
    6·1 answer
  • What is the IEEE 802 standards name for a wireless network that is limited to one person's workspace?
    14·1 answer
  • Xavier buys a new laptop for $540. He makes a down payment $75 and pays the rest in 6 equal monthly payments, p. What equation r
    7·1 answer
  • What are some examples and non-examples of digital security?
    6·1 answer
  • Channel logging tokens can be set to all but:________. a. Relaxed b. Strict c. Both versions d. None
    10·1 answer
  • .NET
    15·1 answer
  • How is a transaction verified on a cryptocurrency network?.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!