We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 8ffadc7 commit 03e6f57Copy full SHA for 03e6f57
18 - Letter Count I.js
@@ -0,0 +1,26 @@
1
+function LetterCountI (str) {
2
+ var words = str.split(' ');
3
+ var largestDif = 0;
4
+ var answer;
5
+
6
+ for (var i = 0; i < words.length; i++) {
7
+ var currentWord = words[i];
8
+ var currentWordLength = words[i].length;
9
+ var currentWordSorted = words[i].split('').sort();
10
+ for (var j = 0; j < (words[i].length - 1); j++) {
11
+ if (currentWordSorted[j] === currentWordSorted[j + 1]) {
12
+ currentWordSorted.splice(j, 1);
13
+ }
14
+ var currentDif = (currentWordLength - currentWordSorted.length);
15
+ if (currentDif > largestDif) {
16
+ largestDif = currentDif;
17
+ answer = currentWord;
18
19
20
21
22
+ if (largestDif > 0) {
23
+ return answer;
24
25
+ return -1;
26
0 commit comments