Skip to content

Conversation

@zyahav
Copy link
Contributor

@zyahav zyahav commented Oct 15, 2016

This is my first exercise.

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

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).

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

Copy link
Owner

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

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)

Copy link
Owner

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).

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

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

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

Copy link
Contributor Author

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

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, ....

Copy link
Contributor Author

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

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

ex1/ex1.js Outdated
//var str = ',,,';// === 2
var str = 'hel,lowo,rld';// === -1

console.log(getThirdCommaPosition(str, ','));
Copy link
Owner

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

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

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

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

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

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

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

function getThirdCommaIndex(str,searcFor) {
function getThirdCommaIndex(str,searchFor) {

var index = -1;
Copy link
Owner

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

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() {

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

ex1/ex1Spec.js Outdated
expect(getThirdCommaIndex('hel,lowo,rld', ',')).toBe(-1);
});

it("hello,world,this,is,a,great,day", function() {
Copy link
Owner

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() {

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

ex1/ex1Spec.js Outdated
expect(getThirdCommaIndex('hello,world,this,is,a,great,day', ',')).toBe(16);
});

it(",,,", function() {
Copy link
Owner

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() {

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

ex1/ex1Spec.js Outdated
@@ -0,0 +1,46 @@
/*
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 not get the require working (or maybe you just did it for another question) and instead you have to copy the function?

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

ex1/ex1.js Outdated

function getThirdCommaIndex(str,searchFor) {

// i do not know how to explain the use of -1
Copy link
Owner

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.

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

ex1/ex1.js Outdated
testFunction('hel,lowo,rld');// === -1
testFunction('hello,world,this,is,a,great,day');// === 16
testFunction(',,,');// === 2
module.exports = { getThirdCommaIndex }
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 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.

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

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

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).

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

@myok12 myok12 changed the title exercise 1 Ex1 Nov 24, 2016
});

it("finds a comma in a regular sentence", function() {
expect(getThirdCommaIndex('hello,world,this,is,a,great,day', ','))
Copy link
Owner

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

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.

myok12 pushed a commit that referenced this pull request Dec 23, 2016
myok12 pushed a commit that referenced this pull request Dec 23, 2016
Merge pull request #2 from myok12/master
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