From 037b8656042376dbf7df8a902091f1607b05ea4a Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Sun, 16 Oct 2016 01:48:29 +0300 Subject: [PATCH 01/10] Manually copied old function --- ex1/ex1.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ex1/ex1.js b/ex1/ex1.js index 5eead9d..0618828 100644 --- a/ex1/ex1.js +++ b/ex1/ex1.js @@ -6,3 +6,25 @@ * fn(",,,") === 2 * fn("hel,lowo,rld") === -1 */ + +///////////////////////////////////////////////////////////////////////////// +// 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; + + for (i = 0; i < 3; i++) { + position = str.indexOf(searcVal, position+1); + if (position == -1) { + break; + } + } + return position; +} + +//var str = 'hello,world,this,is,a,great,day'// === 16 +//var str = ',,,';// === 2 +var str = 'hel,lowo,rld';// === -1 + +console.log(getThirdCommaPosition(str, ',')); +//////////////////////////////////////////////////////////////////////////// From 5ef068fd5d1c73d5d02a4fa0efe0601907a8667e Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Tue, 18 Oct 2016 14:02:22 +0300 Subject: [PATCH 02/10] replace function name from pointer to index replace val to searchFor add test function --- ex1/ex1.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/ex1/ex1.js b/ex1/ex1.js index 0618828..eb083cd 100644 --- a/ex1/ex1.js +++ b/ex1/ex1.js @@ -8,23 +8,27 @@ */ ///////////////////////////////////////////////////////////////////////////// -// getThirdCommaPosition accepts a string and returns the index of the third comma in that string / no comma return -1 -function getThirdCommaPosition(str,searcVal) { +// getThirdCommaIndex accepts a string and returns the index of the third comma in that string / no comma return -1 +function getThirdCommaIndex(str,searcFor) { - var i, position = -1; + var i, index = -1; for (i = 0; i < 3; i++) { - position = str.indexOf(searcVal, position+1); - if (position == -1) { + index = str.indexOf(searcFor, index+1); + if (index == -1) { break; } } - return position; + return index; } -//var str = 'hello,world,this,is,a,great,day'// === 16 -//var str = ',,,';// === 2 -var str = 'hel,lowo,rld';// === -1 -console.log(getThirdCommaPosition(str, ',')); -//////////////////////////////////////////////////////////////////////////// +function testFunction(str) { + + console.log(getThirdCommaIndex(str, ',')); +} + +testFunction('hel,lowo,rld');// === -1 +testFunction('hello,world,this,is,a,great,day');// === 16 +testFunction(',,,');// === 2 +/////////////////////////////////////////////////////////////////////////// From f347958416b66d3a937d8e5a56ef68554e2d6369 Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Mon, 7 Nov 2016 23:24:45 +0200 Subject: [PATCH 03/10] Fixed all initial comments from Ohad --- ex1/ex1.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ex1/ex1.js b/ex1/ex1.js index eb083cd..a5a777e 100644 --- a/ex1/ex1.js +++ b/ex1/ex1.js @@ -8,12 +8,12 @@ */ ///////////////////////////////////////////////////////////////////////////// -// getThirdCommaIndex accepts a string and returns the index of the third comma in that string / no comma return -1 +// 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 i, index = -1; + var index = -1; - for (i = 0; i < 3; i++) { + for (let i = 0; i < 3; i++) { index = str.indexOf(searcFor, index+1); if (index == -1) { break; @@ -22,7 +22,6 @@ function getThirdCommaIndex(str,searcFor) { return index; } - function testFunction(str) { console.log(getThirdCommaIndex(str, ',')); @@ -31,4 +30,3 @@ function testFunction(str) { testFunction('hel,lowo,rld');// === -1 testFunction('hello,world,this,is,a,great,day');// === 16 testFunction(',,,');// === 2 -/////////////////////////////////////////////////////////////////////////// From 3d9da97b0c13bd6a5668554d1035cfc79394687c Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Tue, 15 Nov 2016 14:07:46 +0200 Subject: [PATCH 04/10] 1 --- ex1/ex1.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ex1/ex1.js b/ex1/ex1.js index a5a777e..3d1cd9e 100644 --- a/ex1/ex1.js +++ b/ex1/ex1.js @@ -9,12 +9,12 @@ ///////////////////////////////////////////////////////////////////////////// // getThirdCommaIndex accepts a string and returns the index of the third comma in that string if no comma return -1 -function getThirdCommaIndex(str,searcFor) { +function getThirdCommaIndex(str,searchFor) { var index = -1; for (let i = 0; i < 3; i++) { - index = str.indexOf(searcFor, index+1); + index = str.indexOf(searchFor, index+1); if (index == -1) { break; } From dad124b28ed2a410e4f18a1f75a298d25956a082 Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Tue, 15 Nov 2016 18:30:16 +0200 Subject: [PATCH 05/10] add jasmine test --- ex1/ex1Spec.js | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ex1/ex1Spec.js diff --git a/ex1/ex1Spec.js b/ex1/ex1Spec.js new file mode 100644 index 0000000..f517906 --- /dev/null +++ b/ex1/ex1Spec.js @@ -0,0 +1,46 @@ +/* + * Write a function that accepts a string and returns the index of the third comma in that string. + * If there's no such comma, the function should return -1. + * For example: + * fn("hello,world,this,is,a,great,day") === 16 + * fn(",,,") === 2 + * fn("hel,lowo,rld") === -1 + */ + +///////////////////////////////////////////////////////////////////////////// +// Accepts a string and returns the index of the third comma in that string if no comma return -1 +// +function getThirdCommaIndex(str,searchFor) { + // + // I DO NOT KNOW HOW TO REMOVE THE -1 + // + var index = -1; + + for (var i = 0; i < 3; i++) { + + index = str.indexOf(searchFor, index + 1); + + // If we did not find a comma in str will stop search + if (index == -1) { + break; + } + } + return index; +} + + +describe("getThirdCommaIndex", function() { + + + it("hel,lowo,rld", function() { + expect(getThirdCommaIndex('hel,lowo,rld', ',')).toBe(-1); + }); + + it("hello,world,this,is,a,great,day", function() { + expect(getThirdCommaIndex('hello,world,this,is,a,great,day', ',')).toBe(16); + }); + + it(",,,", function() { + expect(getThirdCommaIndex(',,,', ',')).toBe(2); + }); +}); From f3a43dd60d41a3f32df61435041dea984befbfe7 Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Tue, 22 Nov 2016 07:59:28 +0200 Subject: [PATCH 06/10] redid test using require --- ex1/ex1Spec.js | 43 +++++++------------------------------------ 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/ex1/ex1Spec.js b/ex1/ex1Spec.js index f517906..63eefdd 100644 --- a/ex1/ex1Spec.js +++ b/ex1/ex1Spec.js @@ -1,46 +1,17 @@ -/* - * Write a function that accepts a string and returns the index of the third comma in that string. - * If there's no such comma, the function should return -1. - * For example: - * fn("hello,world,this,is,a,great,day") === 16 - * fn(",,,") === 2 - * fn("hel,lowo,rld") === -1 - */ - -///////////////////////////////////////////////////////////////////////////// -// Accepts a string and returns the index of the third comma in that string if no comma return -1 -// -function getThirdCommaIndex(str,searchFor) { - // - // I DO NOT KNOW HOW TO REMOVE THE -1 - // - var index = -1; - - for (var i = 0; i < 3; i++) { - - index = str.indexOf(searchFor, index + 1); - - // If we did not find a comma in str will stop search - if (index == -1) { - break; - } - } - return index; -} - +var ex1 = require("./ex1"); describe("getThirdCommaIndex", function() { - it("hel,lowo,rld", function() { - expect(getThirdCommaIndex('hel,lowo,rld', ',')).toBe(-1); + it("returns -1 when no third comma", function() { + expect(ex1.getThirdCommaIndex('hel,lowo,rld', ',')).toBe(-1); }); - 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); }); - it(",,,", function() { - expect(getThirdCommaIndex(',,,', ',')).toBe(2); + it("works even when there are no characters beside commas", function() { + expect(ex1.getThirdCommaIndex(',,,', ',')).toBe(2); }); }); From 4a472c17e1acf86d29107eaa438750a0c976dde7 Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Tue, 22 Nov 2016 08:15:49 +0200 Subject: [PATCH 07/10] redid ex1.ja using requirde --- ex1/ex1.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ex1/ex1.js b/ex1/ex1.js index 3d1cd9e..82ad9ff 100644 --- a/ex1/ex1.js +++ b/ex1/ex1.js @@ -8,13 +8,22 @@ */ ///////////////////////////////////////////////////////////////////////////// -// getThirdCommaIndex accepts a string and returns the index of the third comma in that string if no comma return -1 -function getThirdCommaIndex(str,searchFor) { +// Accepts a string and returns the index of the third comma in that string if no comma return -1 +// +// + +function getThirdCommaIndex(str,searchFor) { + + // i do not know how to explain the use of -1 var index = -1; - for (let i = 0; i < 3; i++) { - index = str.indexOf(searchFor, index+1); + for (var i = 0; i < 3; i++) { + + index = str.indexOf(searchFor, index + 1); + + // If we did not find a comma in str will stop search + if (index == -1) { break; } @@ -22,11 +31,4 @@ function getThirdCommaIndex(str,searchFor) { return index; } -function testFunction(str) { - - console.log(getThirdCommaIndex(str, ',')); -} - -testFunction('hel,lowo,rld');// === -1 -testFunction('hello,world,this,is,a,great,day');// === 16 -testFunction(',,,');// === 2 +module.exports = { getThirdCommaIndex } From 1ac33f0d615d70ef4cdd726b7f0cf0635635b011 Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Thu, 1 Dec 2016 12:53:44 +0200 Subject: [PATCH 08/10] typo and break lines --- ex1/ex1Spec.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ex1/ex1Spec.js b/ex1/ex1Spec.js index 63eefdd..5191a31 100644 --- a/ex1/ex1Spec.js +++ b/ex1/ex1Spec.js @@ -2,16 +2,18 @@ var ex1 = require("./ex1"); describe("getThirdCommaIndex", function() { - it("returns -1 when no third comma", function() { - expect(ex1.getThirdCommaIndex('hel,lowo,rld', ',')).toBe(-1); + expect(ex1.getThirdCommaIndex('hel,lowo,rld', ',')) + .toBe(-1); }); - it("finds a comma in a regular sentenc", function() { - expect(ex1.getThirdCommaIndex('hello,world,this,is,a,great,day', ',')).toBe(16); + it("finds a comma in a regular sentence", function() { + expect(ex1.getThirdCommaIndex('hello,world,this,is,a,great,day', ',')) + .toBe(16); }); it("works even when there are no characters beside commas", function() { - expect(ex1.getThirdCommaIndex(',,,', ',')).toBe(2); + expect(ex1.getThirdCommaIndex(',,,', ',')) + .toBe(2); }); }); From 90d5d269c2d4babf4450b859a193521571b50316 Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Thu, 1 Dec 2016 13:40:21 +0200 Subject: [PATCH 09/10] test breack lines --- ex1/ex1.js | 12 ++---------- ex1/ex1Spec.js | 8 ++++---- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/ex1/ex1.js b/ex1/ex1.js index 82ad9ff..6d19e37 100644 --- a/ex1/ex1.js +++ b/ex1/ex1.js @@ -7,23 +7,15 @@ * fn("hel,lowo,rld") === -1 */ -///////////////////////////////////////////////////////////////////////////// -// Accepts a string and returns the index of the third comma in that string if no comma return -1 -// -// - - function getThirdCommaIndex(str,searchFor) { - // i do not know how to explain the use of -1 var index = -1; for (var i = 0; i < 3; i++) { index = str.indexOf(searchFor, index + 1); - // If we did not find a comma in str will stop search - + // If we did not find a comma in str will stop searching if (index == -1) { break; } @@ -31,4 +23,4 @@ function getThirdCommaIndex(str,searchFor) { return index; } -module.exports = { getThirdCommaIndex } +module.exports = getThirdCommaIndex; diff --git a/ex1/ex1Spec.js b/ex1/ex1Spec.js index 5191a31..e6fb0c9 100644 --- a/ex1/ex1Spec.js +++ b/ex1/ex1Spec.js @@ -1,19 +1,19 @@ -var ex1 = require("./ex1"); +var getThirdCommaIndex = require("./ex1"); describe("getThirdCommaIndex", function() { it("returns -1 when no third comma", function() { - expect(ex1.getThirdCommaIndex('hel,lowo,rld', ',')) + expect(getThirdCommaIndex('hel,lowo,rld', ',')) .toBe(-1); }); it("finds a comma in a regular sentence", function() { - expect(ex1.getThirdCommaIndex('hello,world,this,is,a,great,day', ',')) + expect(getThirdCommaIndex('hello,world,this,is,a,great,day', ',')) .toBe(16); }); it("works even when there are no characters beside commas", function() { - expect(ex1.getThirdCommaIndex(',,,', ',')) + expect(getThirdCommaIndex(',,,', ',')) .toBe(2); }); }); From e6095af2eb2fb7ded1c91ab662cbbb1191ae6b81 Mon Sep 17 00:00:00 2001 From: Zuriel Yahav Date: Thu, 1 Dec 2016 21:53:13 +0200 Subject: [PATCH 10/10] add function to test --- ex1/ex1Spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ex1/ex1Spec.js b/ex1/ex1Spec.js index e6fb0c9..3c5310c 100644 --- a/ex1/ex1Spec.js +++ b/ex1/ex1Spec.js @@ -1,6 +1,6 @@ var getThirdCommaIndex = require("./ex1"); -describe("getThirdCommaIndex", function() { +describe("function getThirdCommaIndex", function() { it("returns -1 when no third comma", function() { expect(getThirdCommaIndex('hel,lowo,rld', ','))