Skip to content

Commit f49d525

Browse files
committed
Create Word Count
1 parent 4ad9958 commit f49d525

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Word Count

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/***************************************************************************************
2+
* *
3+
* CODERBYTE BEGINNER CHALLENGE *
4+
* *
5+
* Word Count *
6+
* Using the JavaScript language, have the function WordCount(str) take the str *
7+
* string parameter being passed and return the number of words the string contains *
8+
* (ie. "Never eat shredded wheat" would return 4). Words will be separated by single *
9+
* spaces. *
10+
* *
11+
* SOLUTION *
12+
* I am going to convert str to an Array breaking each word into an Array entry *
13+
* when there is a space. Then return the length of the Array which is the number *
14+
* of words in the string. *
15+
* *
16+
* Steps for solution *
17+
* 1) Convert string to an array breaking on space. *
18+
* 2) Return array length since this is the number of words *
19+
* *
20+
***************************************************************************************/
21+
function WordCount(str) {
22+
23+
return str.split(" ").length;
24+
25+
}

0 commit comments

Comments
 (0)