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
Write a program FindDuplicate.java that reads n integer arguments from the command line into an integer array of length n, where
kozerog [31]

Answer:

  1. public class FindDuplicate{
  2.    public static void main(String[] args) {
  3.        Scanner input = new Scanner(System.in);
  4.        int n = 5;
  5.        int arr[] = new int[n];
  6.        for(int i=0; i < arr.length; i++){
  7.            int inputNum = input.nextInt();
  8.            if(inputNum >=1 && inputNum <=n) {
  9.                arr[i] = inputNum;
  10.            }
  11.        }
  12.        for(int j =0; j < arr.length; j++){
  13.            for(int k = 0; k < arr.length; k++){
  14.                if(j == k){
  15.                    continue;
  16.                }else{
  17.                    if(arr[j] == arr[k]){
  18.                        System.out.println("True");
  19.                        return;
  20.                    }
  21.                }
  22.            }
  23.        }
  24.        System.out.println("False");
  25.    }
  26. }

Explanation:

Firstly, create a Scanner object to get user input (Line 4).

Next, create an array with n-size (Line 7) and then create a for-loop to get user repeatedly enter an integer and assign the input value to the array (Line 9 - 14).

Next, create a double layer for-loop to check the each element in the array against the other elements to see if there is any duplication detected and display "True" (Line 21 - 22). If duplication is found the program will display True and terminate the whole program using return (Line 23). The condition set in Line 18 is to ensure the comparison is not between the same element.

If all the elements in the array are unique the if block (Line 21 - 23) won't run and it will proceed to Line 28 to display message "False".

7 0
3 years ago
What does 32mb SVGA do
Nadya [2.5K]

Answer:

hope it helps PLZ MARK ME BRAINLIEST,,!

Explanation:

They stabilize your grpahic image.

5 0
3 years ago
Which is true of effective passwords?
mylen [45]

Answer:

It is either A. or D.

4 0
3 years ago
The beginning balance of Keyshawn's savings account for the month of September was $3900, and it remained this way for the first
Doss [256]
I’m not gonna wanna was that 638
4 0
3 years ago
Brainly keeps logging me out of my account when I'm on the sign in screen. I put in my email and password and click "log in" and
VLD [36.1K]
Reinstall the app....
3 0
3 years ago
Other questions:
  • While in an interactive nslookup session, you'd use the ______ keyword to change the DNS server you're using
    5·2 answers
  • Technician A says that it's a good idea to perform a test drive before attempting repairs. Technician B says that it's a good id
    9·2 answers
  • The staff of the ___________________ will need to enter, maintain, and retrieve data from electronic health records within a hos
    9·1 answer
  • Select the true statement from the choices below. Group of answer choices Invalid code may cause browsers to render the pages sl
    11·1 answer
  • Powerful IT security systems are needed to defend against what appears to be authorized access to a network or application. Sele
    6·1 answer
  • Explain why it is important to follow a course or a program in keeping with your value system​
    13·1 answer
  • BRAINLIEST FOR CORRECT ANSWERS PLS HELP
    7·2 answers
  • What is an occupation?​
    6·1 answer
  • Which view would you need to use to make changes to the design theme for the entire presentation?
    10·2 answers
  • Using a computer application is known as​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!