forked from ratracegrad/coderbyte-Beginner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWord Count
25 lines (23 loc) · 1.81 KB
/
Word Count
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/***************************************************************************************
* *
* CODERBYTE BEGINNER CHALLENGE *
* *
* Word Count *
* Using the JavaScript language, have the function WordCount(str) take the str *
* string parameter being passed and return the number of words the string contains *
* (ie. "Never eat shredded wheat" would return 4). Words will be separated by single *
* spaces. *
* *
* SOLUTION *
* I am going to convert str to an Array breaking each word into an Array entry *
* when there is a space. Then return the length of the Array which is the number *
* of words in the string. *
* *
* Steps for solution *
* 1) Convert string to an array breaking on space. *
* 2) Return array length since this is the number of words *
* *
***************************************************************************************/
function WordCount(str) {
return str.split(" ").length;
}