File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed
Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ /***************************************************************************************
2+ * *
3+ * CODERBYTE BEGINNER CHALLENGE *
4+ * *
5+ * Letter Count I *
6+ * Using the JavaScript language, have the function FirstFactorial(num) take the num *
7+ * parameter being passed and return the factorial of it (ie. if num = 4, *
8+ * return (4 * 3 * 2 * 1)). For the test cases, the range will be between 1 and 18. * *
9+ * *
10+ * SOLUTION *
11+ * You can either use an iterative or recursive function to solve this challenge. *
12+ * I am going to use an interative function. I am going to start with a value of 1 *
13+ * for my total and then keep multiplying it by the next number until I reach num. *
14+ * *
15+ * This function needs to account for a possible outlier - One and Zero. *
16+ * If num is 1 or 0 then the answer is 1. By setting tot to value of 1 at *
17+ * initialization, then it guaranteees that 1 will be returned if num is ever 0 or 1. *
18+ * Steps for solution *
19+ * 1) Set var tot to 1. *
20+ * 2) Loop from 2 to num and multiple tot by num to get new tot. *
21+ * 3) Return tot for answer. *
22+ * *
23+ ***************************************************************************************/
24+
25+ function LetterCountI(str) {
26+
27+ var words = str.split(" ");
28+ var count = 0;
29+ var word = "";
30+ // code goes here
31+ for (var i = 0; i < words.length; i++) {
32+ var wordx = words[i];
33+ var sum = 0;
34+ for (var j = 0; j < words[i].length; j++) {
35+ var letter = wordx[j];
36+ for (var k = 0; k < wordx.length; k++) {
37+ if ((j != k) && (letter === wordx[k])){
38+ sum += 1;
39+ }
40+ }
41+ }
42+ if (sum > count) {
43+ count = sum;
44+ word = wordx;
45+ }
46+ }
47+ if (count > 0) {
48+ return word;
49+ } else{
50+ return "-1";
51+ }
52+
53+ }
You can’t perform that action at this time.
0 commit comments