Guest User

Untitled

a guest
Jan 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. /*
  2. Flesh out the implementation and test it.
  3.  
  4. Implementation of WHAT, you say? What's the problem statement???
  5.  
  6. Well, you should be able to tell what this code is intended to do just from reading the starter "skeleton".
  7.  
  8. Assuming you find the above statement to be true upon reading the outline, well, then that illustrates the power of good outlining. You don't need a bunch of comments explaining the code. The code is effectively SELF-EXPLANATORY, even at this early, not-fully-implemented stage. This is the level of clarity that you should aim for in your own coding too.
  9.  
  10. ===
  11. *Some notes about the skeleton*
  12.  
  13. When you create such "skeletons" for your own programs, this is a good full-fledged sample to bear in mind.
  14.  
  15. Note the mixture of real "stub" code and pseudocode.
  16.  
  17. The stubs are just a few function names and a few key variable names, not whole for-loops and whatnot.
  18.  
  19. The pseudocode style we want for this purpose is at the level of precise English. It also is not describing for-loops and whatnot. It also is only inside functions. Don't pseudocode functions, just write the functions as empty stubs. That saves you precious time later, with less rewriting.
  20.  
  21. */
  22.  
  23. function findMaxRepeatCountInWord(word) {
  24. // Break up individual words into individual letters.
  25. // Count the instances of each letter
  26. // Iterate all the counts and find the highest
  27. // Return this word's max repeat count
  28. var a = word.split("")
  29. var counter = 1
  30. var final = 0;
  31. for(var i = 1;i< a.length;i++){
  32. if(word[i] != word[i-1]){
  33. if(counter > final){
  34. final = counter
  35. }
  36. } else {
  37. counter++;
  38. }
  39. }
  40. return counter
  41. }
  42.  
  43. function findFirstWordWithMostRepeatedChars(text) {
  44. var maxRepeatCountOverall = 0;
  45. var wordWithMaxRepeatCount = '';
  46.  
  47. // Break up input text into words (space-delimited).
  48. // For each word...
  49. text.forEach(function(word){
  50. var repeatCountForWord = findMaxRepeatCountInWord(word)
  51. if(repeatCountForWord > maxRepeatCountOverall){
  52. wordWithMaxRepeatCount = word;
  53. maxRepeatCountOverall = repeatCountForWord;
  54. }
  55. })
  56.  
  57. // If that max repeat count is higher than the overall max repeat count, then
  58. // update maxRepeatCountOverall
  59. // update wordWithMaxRepeatCount
  60.  
  61. return wordWithMaxRepeatCount;
  62. }
  63.  
  64. findFirstWordWithMostRepeatedChars(["aaada" ,"fff", "q", "eeee"])
Add Comment
Please, Sign In to add comment