Skip to content

Commit

Permalink
Merge pull request #46 from Naosha/master
Browse files Browse the repository at this point in the history
Max Character Exercise
  • Loading branch information
bradtraversy committed Jan 20, 2020
2 parents 054c4c4 + 2da2966 commit 2690da7
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions session1/index_extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,33 @@ function maxCharacter(str) {
// return maxChar.char;
}

//Solution by Naomi Sharp
//Fixes bug in above solution for which the string "socks" would not work. This is because
//the char "s" is the last one in the array sortedStr so the code to store maxChar does not run.

function maxCharacter(str) {
// const sortedStr = str.split('').sort();
// const maxChar = {char: '', count: 0};
// const currentChar = {char: '', count: 0};

// sortedStr.forEach(char => {
// if(currentChar.char === char){
// currentChar.count++;
// if(maxChar.count < currentChar.count){
// maxChar.char = currentChar.char;
// maxChar.count = currentChar.count;
// }
// currentChar.char = char;
// currentChar.count = 0;
// } else {
// currentChar.char = char;
// currentChar.count = 1;
// }
// });

// return maxChar.char;
}

// CHALLENGE 6: FIZZBUZZ
// Write a program that prints all the numbers from 1 to 100. For multiples of 3, instead of the number, print "Fizz", for multiples of 5 print "Buzz". For numbers which are multiples of both 3 and 5, print "FizzBuzz".
function fizzBuzz() {
Expand Down Expand Up @@ -289,6 +316,8 @@ function maxCharacter(str) {
// }
// });
// return maxChar.char;


// CONTRIBUTED SOLUTION
// BY Romain Guilloteau
// let letters = {};
Expand Down

0 comments on commit 2690da7

Please sign in to comment.