-
Notifications
You must be signed in to change notification settings - Fork 1
Ex1 #2
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?
Ex1 #2
Conversation
ex1/ex1.js
Outdated
|
|
||
| ///////////////////////////////////////////////////////////////////////////// | ||
| // getThirdCommaPosition accepts a string and returns the index of the third comma in that string / no comma return -1 | ||
| function getThirdCommaPosition(str,searcVal) { |
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.
searchVal was not requested in the question, but fine.
BTW - searcVal --> searchVal (with h).
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
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.
Still not fixed
ex1/ex1.js
Outdated
|
|
||
| ///////////////////////////////////////////////////////////////////////////// | ||
| // getThirdCommaPosition accepts a string and returns the index of the third comma in that string / no comma return -1 | ||
| function getThirdCommaPosition(str,searcVal) { |
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.
Position is fine, but in JavaScript we normally use the word index (like in indexOf)
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 (next time you add this comment so that I know this is fine now).
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
ex1/ex1.js
Outdated
| // getThirdCommaPosition accepts a string and returns the index of the third comma in that string / no comma return -1 | ||
| function getThirdCommaPosition(str,searcVal) { | ||
|
|
||
| var i, position = -1; |
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.
The -1 assignment is not needed, but it's fine
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.
need more info
ex1/ex1.js
Outdated
|
|
||
| var i, position = -1; | ||
|
|
||
| for (i = 0; i < 3; 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.
if you are writing in ES6, I would move the var statement into the for loop and change it to a let, as in for (let i = 0, ....
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.
position = -1; בגלל שצריך להתחיל מ 0
position = str.indexOf(searcVal, position+1);
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
ex1/ex1.js
Outdated
| //var str = ',,,';// === 2 | ||
| var str = 'hel,lowo,rld';// === -1 | ||
|
|
||
| console.log(getThirdCommaPosition(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.
Please make a function that tests using console log, e.g.:
function testFunction(str) {
console.log(getThirdCommaPosition(str));
}
and call it as many times as your examples
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
replace val to searchFor add test function
ex1/ex1.js
Outdated
|
|
||
| ///////////////////////////////////////////////////////////////////////////// | ||
| // getThirdCommaIndex accepts a string and returns the index of the third comma in that string if no comma return -1 | ||
| function getThirdCommaIndex(str,searcFor) { |
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.
searchFor
| // getThirdCommaIndex accepts a string and returns the index of the third comma in that string if no comma return -1 | ||
| function getThirdCommaIndex(str,searcFor) { | ||
|
|
||
| var index = -1; |
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.
The initial value of -1 isn't being used
ex1/ex1.js
Outdated
|
|
||
| function testFunction(str) { | ||
|
|
||
| console.log(getThirdCommaIndex(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.
Please switch to console.assert.
Then, read https://jasmine.github.io/ and switch to a real test framework (after which, running npm test should test your code and report if anything is wrong. Good luck
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
| function getThirdCommaIndex(str,searcFor) { | ||
| function getThirdCommaIndex(str,searchFor) { | ||
|
|
||
| var index = -1; |
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.
Please put a comment about why the value -1 is important.
ex1/ex1Spec.js
Outdated
| describe("getThirdCommaIndex", function() { | ||
|
|
||
|
|
||
| it("hel,lowo,rld", function() { |
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.
The it name should reflect what you are testing for. It should be some sentence, such as: "it returns -1 when no third comma", and should be then written as it("returns -1 when no third comma", function() {
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
ex1/ex1Spec.js
Outdated
| expect(getThirdCommaIndex('hel,lowo,rld', ',')).toBe(-1); | ||
| }); | ||
|
|
||
| it("hello,world,this,is,a,great,day", function() { |
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.
it("finds a comma in a regular sentence", function() {
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
ex1/ex1Spec.js
Outdated
| expect(getThirdCommaIndex('hello,world,this,is,a,great,day', ',')).toBe(16); | ||
| }); | ||
|
|
||
| it(",,,", function() { |
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.
it("works even when there are no characters beside commas", function() {
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
ex1/ex1Spec.js
Outdated
| @@ -0,0 +1,46 @@ | |||
| /* | |||
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 not get the require working (or maybe you just did it for another question) and instead you have to copy the function?
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
ex1/ex1.js
Outdated
|
|
||
| function getThirdCommaIndex(str,searchFor) { | ||
|
|
||
| // i do not know how to explain the use of -1 |
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 should have been in a github comment and not in code. (You don't really want this to remain in code for the next time you'll go read this, right?) Please delete.
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
ex1/ex1.js
Outdated
| testFunction('hel,lowo,rld');// === -1 | ||
| testFunction('hello,world,this,is,a,great,day');// === 16 | ||
| testFunction(',,,');// === 2 | ||
| module.exports = { getThirdCommaIndex } |
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 equivalent to:
module.exports = { getThirdCommaIndex: getThirdCommaIndex }
This exports an object with one property named getThirdCommaIndex.
Since you don't need to export anything else, you can just export the function directly:
module.exports = getThirdCommaIndex
The test file will have to change too, obviously.
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
ex1/ex1Spec.js
Outdated
| it("hello,world,this,is,a,great,day", function() { | ||
| expect(getThirdCommaIndex('hello,world,this,is,a,great,day', ',')).toBe(16); | ||
| it("finds a comma in a regular sentenc", function() { | ||
| expect(ex1.getThirdCommaIndex('hello,world,this,is,a,great,day', ',')).toBe(16); |
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.
Try to break lines in higher-level constructs:
expect(ex1.getThirdCommaIndex('hello,world,this,is,a,great,day', ','))
.toBe(16);
It makes it easier to read (the pause of the line break comes in a better place).
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
| }); | ||
|
|
||
| it("finds a comma in a regular sentence", function() { | ||
| expect(getThirdCommaIndex('hello,world,this,is,a,great,day', ',')) |
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.
The maximum line length on github.com is 80 character, so this line gets too long. You could break this into two lines, but I think it might be easier to use a shorter tab (maybe two spaces instead of an entire tab? See https://www.google.com/search?sourceid=chrome-psyapi2&ion=1&espv=2&ie=UTF-8&q=vim%20tabs%20to%20spaces&oq=vim%20tab&aqs=chrome.1.69i57j0l5.3624j0j7
|
|
||
| it("works even when there are no characters beside commas", function() { | ||
| expect(getThirdCommaIndex(',,,', ',')) | ||
| .toBe(2); |
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.
When you do break a line because it is long, you need to push the continuation line in: +tab.
Merge pull request #2 from myok12/master
This is my first exercise.