-
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
Changes from all commits
037b865
5ef068f
f347958
3d9da97
dad124b
f3a43dd
4a472c1
1ac33f0
90d5d26
e6095af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,21 @@ | |
| * fn(",,,") === 2 | ||
| * fn("hel,lowo,rld") === -1 | ||
| */ | ||
|
|
||
| function getThirdCommaIndex(str,searchFor) { | ||
|
|
||
| var index = -1; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please put a comment about why the value -1 is important. |
||
|
|
||
| for (var i = 0; i < 3; i++) { | ||
|
|
||
| index = str.indexOf(searchFor, index + 1); | ||
|
|
||
| // If we did not find a comma in str will stop searching | ||
| if (index == -1) { | ||
| break; | ||
| } | ||
| } | ||
| return index; | ||
| } | ||
|
|
||
| module.exports = getThirdCommaIndex; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| var getThirdCommaIndex = require("./ex1"); | ||
|
|
||
| describe("function getThirdCommaIndex", function() { | ||
|
|
||
| it("returns -1 when no third comma", function() { | ||
| expect(getThirdCommaIndex('hel,lowo,rld', ',')) | ||
| .toBe(-1); | ||
| }); | ||
|
|
||
| it("finds a comma in a regular sentence", function() { | ||
| expect(getThirdCommaIndex('hello,world,this,is,a,great,day', ',')) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| .toBe(16); | ||
| }); | ||
|
|
||
| it("works even when there are no characters beside commas", function() { | ||
| expect(getThirdCommaIndex(',,,', ',')) | ||
| .toBe(2); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| }); | ||
| }); | ||
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