Skip to content

Conversation

@zyahav
Copy link
Contributor

@zyahav zyahav commented Dec 6, 2016

No description provided.

ex7/ex7.js Outdated
search = { charValue: '', charCount: 0},
doNotSearchList = [];

if (str != '') {
Copy link
Owner

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;
}

Copy link
Contributor Author

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++) {
Copy link
Owner

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?

Copy link
Contributor Author

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);
Copy link
Owner

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.

Copy link
Owner

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);
Copy link
Owner

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 === '') {
Copy link
Owner

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 = {};
Copy link
Owner

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);
Copy link
Owner

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;
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants