File tree Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Expand file tree Collapse file tree 1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments