-
Notifications
You must be signed in to change notification settings - Fork 1
Ex7 b #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Ex7 b #13
Conversation
ex7/ex7.js
Outdated
| search = { charValue: '', charCount: 0}, | ||
| doNotSearchList = []; | ||
|
|
||
| if (str != '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to do this instead, because then the edge-case is being considered at the top, while the rest of the code remain simple (i.e. without the indentation):
if (str === '') {
return null;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
ex7/ex7.js
Outdated
| if (str != '') { | ||
|
|
||
| // Loop through all chars in str | ||
| for (var i = 0; i < str.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened to our let?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jasmine version do not have let
ex7/ex7.js
Outdated
| doNotSearchList.push(search.charValue); | ||
|
|
||
| index = 1; | ||
| index = str.indexOf(search.charValue, i + index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as in the other question -- this will be O(n*n) = O(n^2) order of n squared. Switch to object-based searching instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you do this?
ex7/ex7.js
Outdated
| doNotSearchList.push(search.charValue); | ||
|
|
||
| index = 1; | ||
| index = str.indexOf(search.charValue, i + index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you do this?
|
|
||
| objCharCount = {}; | ||
|
|
||
| if (str === '') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do this if first, before the objCharCount = {};
|
|
||
| function mostFrequentChar(str) { | ||
|
|
||
| objCharCount = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing var -- this is now defined on the window :(
| for (var i = 0; i < str.length; i++) { | ||
|
|
||
| // The char we are now working on | ||
| currentChar = str.charAt(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing var.
|
|
||
| } else if (maxCount === currentCount) { | ||
|
|
||
| frequentChar = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not clear. I would instead add another variable called moreThanOneMax and set it to true here (then check for it below).
Also, I think this will fail on this instance: 1122333.
No description provided.