From 8db8292ea9fbce89851439839566bf289612db9a Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 15:29:17 -0500 Subject: [PATCH 01/19] Problem1.js has been solved --- problems/problem1.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/problems/problem1.js b/problems/problem1.js index 6d7505c..0e461c0 100644 --- a/problems/problem1.js +++ b/problems/problem1.js @@ -2,16 +2,26 @@ var assert = require('assert'); // we need 5 test cases. I provided 1 input let inputs = [ - "" + "", + "abc", + "cba", + "123", + "321" ] let outputs = [ - + undefined, + "a", + "c", + "1", + "3" ] // Make this function return the first letter of the string that is passed to it. If the string does not have a first letter, return undefined function f(str) { - + var array = str.split(""); + var firstLetter = array[0]; + return firstLetter; } function runTest(i) { @@ -24,4 +34,4 @@ runTest(0); runTest(1); runTest(2); runTest(3); -runTest(4); +runTest(4); \ No newline at end of file From dda2592abab764af1170fa589ac38b0b49bb0c16 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 15:41:31 -0500 Subject: [PATCH 02/19] The second problem has been solved --- problems/problem2.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/problems/problem2.js b/problems/problem2.js index d54ae74..c15dd60 100644 --- a/problems/problem2.js +++ b/problems/problem2.js @@ -2,16 +2,27 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - + "", + "abc", + "cba", + "123", + "321" ] let outputs = [ - + undefined, + "c", + "a", + "3", + "1" ] // Make this function return the last letter of the string that is passed to it. If the string does not have a last letter, return undefined function f(str) { - + var array = str.split(""); + var reversed = array.reverse(); + var firstLetter = reversed[0]; + return firstLetter; } function runTest(i) { From 03e61c09f2da7966bf4cb590b365ed12d478033b Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 17:15:56 -0500 Subject: [PATCH 03/19] Problem3.js is solved --- problems/problem3.js | 28 +++++++++++++++++++++------- problems/problem4.js | 8 +++++++- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/problems/problem3.js b/problems/problem3.js index 11358c6..93177f9 100644 --- a/problems/problem3.js +++ b/problems/problem3.js @@ -3,25 +3,39 @@ var assert = require('assert'); // we need 7 test cases. I've provided 2. let inputs = [ [2, 4], - [-3, 3] + [-3, 3], + ["", 3], + ["ididn", 3], + [5, 54], + [5, 2], + [10, 4] ] let outputs = [ 6, - 0 + 0, + undefined, + undefined, + 59, + 7, + 14 ] /* Make this function return the sum of the two numbers that are passed to it. If one of the numbers is not passed, or if anything other than numbers are passed, return undefined. */ -function f(x, y) { - +function f(x) { + if ((!isNaN(x[0]) && !isNaN(x[1])) && (x[0] !== (""||'') && x[1] !== (""||''))){ + var result = x[0] + x[1]; + return result; + } + return undefined; } function runTest(i) { - var expected = outputs[i]; - var actual = f(inputs[i]); - assert.deepEqual(actual, expected); + var expected = outputs[i]; + var actual = f(inputs[i]); + assert.deepEqual(actual, expected); } runTest(0); diff --git a/problems/problem4.js b/problems/problem4.js index 4082082..f5b42c9 100644 --- a/problems/problem4.js +++ b/problems/problem4.js @@ -3,7 +3,13 @@ var assert = require('assert'); // we need 8 test cases. I've provided the first 2 let inputs = [ ["hello", 4], - ["", 2] + ["", 2], + ["abc", 1], + ["chess", 3], + ["car", 2], + ["doggy", 3], + ["felt", 3], + ["chocolate", 5], ] let outputs = [ From a3e0b5418fb9b10f12210e6a8e9d5e81e869e63d Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 17:32:39 -0500 Subject: [PATCH 04/19] Problem4.js solved --- problems/problem4.js | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/problems/problem4.js b/problems/problem4.js index f5b42c9..f73ec8a 100644 --- a/problems/problem4.js +++ b/problems/problem4.js @@ -14,20 +14,27 @@ let inputs = [ let outputs = [ "o", - undefined + undefined, + "b", + "s", + "r", + "g", + "t", + "l" ] /* Make this function return the letter at the specified position in the string. If no such letter exists, it should return undefined. - For example: -f("hello", 1); // e -f("", 4); // undefined -f("abc", 0); // a - +f(["hello", 1]); // e +f(["", 4]); // undefined +f(["abc", 0]); // a */ -function f(str, index) { - +function f(str, num) { + if(str.length === 0) return undefined; + var index = str.charAt(num); + if(index === 0) return undefined; + return index; } function runTest(i) { @@ -44,4 +51,4 @@ runTest(3); runTest(4); runTest(5); runTest(6); -runTest(7); +runTest(7); \ No newline at end of file From 21a86042aba2186a7224992ebaa45d301ab57c49 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 17:46:47 -0500 Subject: [PATCH 05/19] Problem5.js solved --- problems/problem1.js | 12 ++++++------ problems/problem3.js | 2 +- problems/problem4.js | 12 ++++++------ problems/problem5.js | 28 ++++++++++++++++++++-------- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/problems/problem1.js b/problems/problem1.js index 0e461c0..96c2d65 100644 --- a/problems/problem1.js +++ b/problems/problem1.js @@ -19,15 +19,15 @@ let outputs = [ // Make this function return the first letter of the string that is passed to it. If the string does not have a first letter, return undefined function f(str) { - var array = str.split(""); - var firstLetter = array[0]; - return firstLetter; + var array = str.split(""); + var firstLetter = array[0]; + return firstLetter; } function runTest(i) { - var expected = outputs[i]; - var actual = f(inputs[i]); - assert.deepEqual(actual, expected); + var expected = outputs[i]; + var actual = f(inputs[i]); + assert.deepEqual(actual, expected); } runTest(0); diff --git a/problems/problem3.js b/problems/problem3.js index 93177f9..fb5c8f4 100644 --- a/problems/problem3.js +++ b/problems/problem3.js @@ -25,7 +25,7 @@ let outputs = [ Make this function return the sum of the two numbers that are passed to it. If one of the numbers is not passed, or if anything other than numbers are passed, return undefined. */ function f(x) { - if ((!isNaN(x[0]) && !isNaN(x[1])) && (x[0] !== (""||'') && x[1] !== (""||''))){ + if ((!isNaN(x[0]) && !isNaN(x[1])) && (x[0] !== ("" || '') && x[1] !== ("" || ''))) { var result = x[0] + x[1]; return result; } diff --git a/problems/problem4.js b/problems/problem4.js index f73ec8a..0056263 100644 --- a/problems/problem4.js +++ b/problems/problem4.js @@ -31,17 +31,17 @@ f(["", 4]); // undefined f(["abc", 0]); // a */ function f(str, num) { - if(str.length === 0) return undefined; + if (str.length === 0) return undefined; var index = str.charAt(num); - if(index === 0) return undefined; + if (index === 0) return undefined; return index; } function runTest(i) { - var expected = outputs[i]; - var input = inputs[i]; - var actual = f(input[0], input[1]); - assert.deepEqual(actual, expected); + var expected = outputs[i]; + var input = inputs[i]; + var actual = f(input[0], input[1]); + assert.deepEqual(actual, expected); } runTest(0); diff --git a/problems/problem5.js b/problems/problem5.js index b1e2e44..5e24b59 100644 --- a/problems/problem5.js +++ b/problems/problem5.js @@ -2,25 +2,37 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - [2, 7] + [2, 7], + [3, 3], + ["ifjew", 5], + [5, 10], + [4, ''] ] let outputs = [ - 14 + 14, + 9, + undefined, + 50, + undefined ] /* Make this function return the product of the two numbers that are passed to it. If one of the numbers is not passed, or if anything other than numbers are passed, return undefined. */ -function f(x, y) { - +function f(x) { + if ((!isNaN(x[0]) && !isNaN(x[1])) && (x[0] !== ("" || '') && x[1] !== ("" || ''))){ + var result = x[0]*x[1]; + return result; + } + return undefined; } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); - var expected = outputs[i]; - var actual = f(inputs[i]); - assert.deepEqual(actual, expected); + if (i > inputs.length) throw new Error("You do not have enough test cases"); + var expected = outputs[i]; + var actual = f(inputs[i]); + assert.deepEqual(actual, expected); } runTest(0); From a78a199ecf49f43d5731ea387527a354295011f2 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 17:56:09 -0500 Subject: [PATCH 06/19] Problem6.js solved --- problems/.vscode/launch.json | 14 ++++++++++ problems/problem6.js | 51 +++++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 13 deletions(-) create mode 100644 problems/.vscode/launch.json diff --git a/problems/.vscode/launch.json b/problems/.vscode/launch.json new file mode 100644 index 0000000..7cca2fa --- /dev/null +++ b/problems/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Launch Program", + "program": "${workspaceFolder}/problem6.js" + } + ] +} \ No newline at end of file diff --git a/problems/problem6.js b/problems/problem6.js index d31ae17..1d6e394 100644 --- a/problems/problem6.js +++ b/problems/problem6.js @@ -4,11 +4,20 @@ var assert = require('assert'); // we need 6 test cases. let inputs = [ ["add", 10, 20], - ["chair", 20, 10] + ["chair", 20, 10], + ["mult", 5, 10], + ["sub", 4, 6], + ["add", 30, 4], + ["mult", 3, 3] ] let outputs = [ - 30 + 30, + undefined, + 50, + -2, + 34, + 9 ] /* @@ -16,20 +25,36 @@ Use the operation argument to decide what this function will return. If it's "add", return the sum of the two numbers. "sub" return their difference. "mult" return their product. Anything else return undefined. For example: -f("add", 10, 20); // 30 -f("mult", 2, 3); // 6 -f("spoof", 10, 10); // undefined - +f(["add", 10, 20]); // 30 +f(["mult", 2, 3]); // 6 +f(["spoof", 10, 10]); // undefined */ -function f(operation, firstArgument, secondArgument) { - +function f(arr) { + var result; + + switch (arr[0]) { + case "add": + result = arr[1] + arr[2]; + return result; + + case "sub": + result = arr[1] - arr[2]; + return result; + + case "mult": + result = arr[1] * arr[2]; + return result; + + default: + return undefined; + } } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); - var expected = outputs[i]; - var actual = f(inputs[i]); - assert.deepEqual(actual, expected); + if (i > inputs.length) throw new Error("You do not have enough test cases"); + var expected = outputs[i]; + var actual = f(inputs[i]); + assert.deepEqual(actual, expected); } runTest(0); @@ -37,4 +62,4 @@ runTest(1); runTest(2); runTest(3); runTest(4); -runTest(5); +runTest(5); \ No newline at end of file From 22a875fe2d32175e3f3afb7946644b527bfbfd51 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 18:41:56 -0500 Subject: [PATCH 07/19] Problem7.js is solved --- problems/problem7.js | 42 +++++++++++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/problems/problem7.js b/problems/problem7.js index c3bf4b1..b489f98 100644 --- a/problems/problem7.js +++ b/problems/problem7.js @@ -2,29 +2,50 @@ var assert = require('assert'); // we need 7 test cases. let inputs = [ - + [24, 4], + ["hubba", 3], + ["boots and cats ", 10], + ["racecar", 3], + ["lol", ""], + ["yolo", 0], + ["BLARGH!", -2] ] let outputs = [ - + undefined, + "hubbahubbahubba", + "boots and cats boots and cats boots and cats boots and cats boots and cats boots and cats boots and cats boots and cats boots and cats boots and cats ", + "racecarracecarracecar", + undefined, + "", + "" ] /* Make this function return the input string repeated as many times as specified. If a negative number or zero is specified, return an empty string. If any invalid parameters are supplied return undefined. - For example: - -f("foo", 3) // "foofoofoo" -f("fo", 3) // "fofofo" -f("foo", -1) // undefined +f(["foo", 3]) // "foofoofoo" +f(["fo", 3]) // "fofofo" +f(["foo", -1]) // undefined */ -function f(str, n) { - +function f(arr) { + var str = ""; + + if ((!isNaN(arr[0])) || (arr[1] === ("" || ''))) return undefined; + + else if ((arr[1] <= 0) && !isNaN(arr[1])) return str; + + else if ((isNaN(arr[0]) && arr[0] !== ("" || '')) && !isNaN(arr[1])) { + str = arr[0].repeat(arr[1]); + return str; + } + + return undefined; } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); + if (i > inputs.length) throw new Error("You do not have enough test cases"); var expected = outputs[i]; var actual = f(inputs[i]); assert.deepEqual(actual, expected); @@ -37,4 +58,3 @@ runTest(3); runTest(4); runTest(5); runTest(6); - From d13d1662a2195651e09cc840efa209684e56ddd9 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 18:55:28 -0500 Subject: [PATCH 08/19] Problem8.js is solved --- problems/problem8.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/problems/problem8.js b/problems/problem8.js index 6165932..cc7dc28 100644 --- a/problems/problem8.js +++ b/problems/problem8.js @@ -2,11 +2,19 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - + "racecar", + "butter", + "computer", + "jar", + "bottom" ] let outputs = [ - + "racecar", + "rettub", + "retupmoc", + "raj", + "mottob" ] /* @@ -14,7 +22,13 @@ Make this function return the input string, reversed. For example "hello" would You must use a for loop for this exercise. */ function f(str) { + var newStr = str.split(''); + var newWord = []; + for(var i = 0; i<=str.length; ++i){ + newWord.push(newStr[str.length - i]); + } + return newWord.join(''); } function runTest(i) { From c94514b18c85fdc6130097b262d58e23b05f4c64 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 19:06:17 -0500 Subject: [PATCH 09/19] Problem9.js is solved --- problems/problem9.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/problems/problem9.js b/problems/problem9.js index 5c52ef5..0ceb3f2 100644 --- a/problems/problem9.js +++ b/problems/problem9.js @@ -2,11 +2,19 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - + "hi", + "", + "Hello my anticonstitutionnalisationnable people", + "One two three", + "Racecar up side down is racecar" ] let outputs = [ - + "hi", + "", + "anticonstitutionnalisationnable", + "three", + "racecar" ] /* @@ -14,7 +22,12 @@ Make this function return the longest word in the input string. If the input str If multiple words have the same length, return the last one that matches. */ function f(str) { - + str.split(" ").toLowerCase(); + var lgStr = ""; + for(var i = 0; i < str.length; ++i){ + if(lgStr.length <= str[i].length) lgStr = str[i]; + } + return lgStr; } function runTest(i) { From 383f84d0e8d059ca314790ceebd7c6d5695f20bd Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 19:47:21 -0500 Subject: [PATCH 10/19] Problem10.js is solved --- problems/problem10.js | 28 ++++++++++++++++++++++++---- problems/problem9.js | 26 +++++++++++++------------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/problems/problem10.js b/problems/problem10.js index e7eddde..013c379 100644 --- a/problems/problem10.js +++ b/problems/problem10.js @@ -2,11 +2,19 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - + "Hello world", + "Bonjour le monde", + "ola sénorita", + "hELLO eVERYONE iN tHE wORLD", + "Koalas are cool" ] let outputs = [ - + "Hello World", + "Bonjour Le Monde", + "Ola Sénorita", + "Hello Everyone In The World", + "Koalas Are Cool" ] /* @@ -17,11 +25,23 @@ f("ALL YOUR BASE ARE BELONG"); // All Your Base Are Belong */ function f(str) { - + var arr = str.toLowerCase().split(" "); + var firstChar = ""; + var capWord = ""; + var newArr = []; + + for (var i = 0; i < arr.length; ++i) { + firstChar = arr[i].toUpperCase().charAt(0); + capWord = firstChar + arr[i].substring(1, arr[i].length); + newArr.push(capWord); + } + + var newStr = newArr.join(" "); + return newStr; } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); + if (i > inputs.length) throw new Error("You do not have enough test cases"); var expected = outputs[i]; var actual = f(inputs[i]); assert.deepEqual(actual, expected); diff --git a/problems/problem9.js b/problems/problem9.js index 0ceb3f2..0f34d6e 100644 --- a/problems/problem9.js +++ b/problems/problem9.js @@ -2,19 +2,19 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - "hi", - "", - "Hello my anticonstitutionnalisationnable people", - "One two three", - "Racecar up side down is racecar" + "hi", + "", + "Hello my anticonstitutionnalisationnable people", + "One two three", + "Racecar up side down is racecar" ] let outputs = [ - "hi", - "", - "anticonstitutionnalisationnable", - "three", - "racecar" + "hi", + "", + "anticonstitutionnalisationnable", + "three", + "racecar" ] /* @@ -24,14 +24,14 @@ If multiple words have the same length, return the last one that matches. function f(str) { str.split(" ").toLowerCase(); var lgStr = ""; - for(var i = 0; i < str.length; ++i){ - if(lgStr.length <= str[i].length) lgStr = str[i]; + for (var i = 0; i < str.length; ++i) { + if (lgStr.length <= str[i].length) lgStr = str[i]; } return lgStr; } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); + if (i > inputs.length) throw new Error("You do not have enough test cases"); var expected = outputs[i]; var actual = f(inputs[i]); assert.deepEqual(actual, expected); From 7546dc0e425886792a54735f5ae9682a143fc985 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 20:29:21 -0500 Subject: [PATCH 11/19] Problem11.js is solved --- problems/problem11.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/problems/problem11.js b/problems/problem11.js index a9db8bc..8cfec3a 100644 --- a/problems/problem11.js +++ b/problems/problem11.js @@ -2,22 +2,40 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - + [10, 3, 5, 3, 2], + [4, 3, 1, 6, 4, 2, 4], + [5, 3, 7, 9, 5, 6], + ["hi", 4, 6, 3, 2, "", 5], + [] ] let outputs = [ - + 23, + 24, + 35, + 20, + 0 ] /* Make this function return the sum of all the numbers in the input array. If any element in the array is not a number, skip it. If the array is empty, return zero. */ function f(arr) { + if (0 === arr.length) return 0; + + for (var i = 0; i < arr.length; ++i) { + if ((isNaN(arr[i]) || arr[i] === ("" || ''))) { + arr.splice(i, 1, 0); + } + } + return arr.reduce(function(a,b){ + return a+b; + }); } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); + if (i > inputs.length) throw new Error("You do not have enough test cases"); var expected = outputs[i]; var actual = f(inputs[i]); assert.deepEqual(actual, expected); From 4daf2e191d44a75ad0cfa81be6b501a76ddd8bba Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 20:56:56 -0500 Subject: [PATCH 12/19] Problem13.js is solved --- problems/problem11.js | 6 +++--- problems/problem12.js | 22 +++++++++++++++++----- problems/problem13.js | 27 +++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/problems/problem11.js b/problems/problem11.js index 8cfec3a..1478453 100644 --- a/problems/problem11.js +++ b/problems/problem11.js @@ -28,9 +28,9 @@ function f(arr) { arr.splice(i, 1, 0); } } - - return arr.reduce(function(a,b){ - return a+b; + + return arr.reduce(function (a, b) { + return a + b; }); } diff --git a/problems/problem12.js b/problems/problem12.js index 2947d1b..6cd33e2 100644 --- a/problems/problem12.js +++ b/problems/problem12.js @@ -2,11 +2,19 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - + [[1, 2, 3], [4, 5, 6]], + [[1, 2, 3, 4, 5, 6], [4, 5, 6]], + [[1, 2, 3], [1, 2, 3, 4, 5, 6]], + ["hi", [1, 2, 3]], + [[1, 2, 3, 5], [2, 4, 5, 6]] ] let outputs = [ - + [1, 2, 3, 4, 5, 6], + [1, 2, 3], + [4, 5, 6], + undefined, + [1, 3, 4, 6] ] /* @@ -19,12 +27,16 @@ uniqueElements([0,1,2,3], [1,3,4,5]); // [0,4,5] uniqueElements([1,2,3], [1,2,3]); // [] uniqueElements(2,3); // undefined, not arrays */ -function f(arr1, arr2) { - +function f(arr) { + for(var i = 0; i < arr[0].length; ++i){ + for(var z = 0; z < arr[1].length; ++i){ + + } + } } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); + if (i > inputs.length) throw new Error("You do not have enough test cases"); var expected = outputs[i]; var actual = f(inputs[i]); assert.deepEqual(actual, expected); diff --git a/problems/problem13.js b/problems/problem13.js index 90669e3..c7376d3 100644 --- a/problems/problem13.js +++ b/problems/problem13.js @@ -2,11 +2,19 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - + "racecar", + "butter", + "computer", + "kayak", + "bottom" ] let outputs = [ - + true, + false, + false, + true, + false ] /* @@ -16,11 +24,22 @@ RADAR -> Yes JAVASCRIPT -> No */ function f(str) { - + var a = str; + var newStr = str.split(''); + var newWord = []; + for (var i = 0; i <= str.length; ++i) { + newWord.push(newStr[str.length - i]); + } + + var b = newWord.join(''); + + if (a == b) return true; + + else return false; } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); + if (i > inputs.length) throw new Error("You do not have enough test cases"); var expected = outputs[i]; var actual = f(inputs[i]); assert.deepEqual(actual, expected); From 4577a679cf9edae2d2d1cf3942c56c432de2c29b Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 21:57:28 -0500 Subject: [PATCH 13/19] Problem14.js is solved --- problems/problem12.js | 8 ++++---- problems/problem14.js | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/problems/problem12.js b/problems/problem12.js index 6cd33e2..e0b786b 100644 --- a/problems/problem12.js +++ b/problems/problem12.js @@ -28,11 +28,11 @@ uniqueElements([1,2,3], [1,2,3]); // [] uniqueElements(2,3); // undefined, not arrays */ function f(arr) { - for(var i = 0; i < arr[0].length; ++i){ - for(var z = 0; z < arr[1].length; ++i){ + Array.isArray(arr[0]) && Array.isArray(arr[1]) - } - } + concat(array) + + filter(e =>) } function runTest(i) { diff --git a/problems/problem14.js b/problems/problem14.js index eb49b73..147259e 100644 --- a/problems/problem14.js +++ b/problems/problem14.js @@ -2,11 +2,19 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - + "01234567890123456789012345678901234567890123456789012345678901234567890123456789", + "0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789", + "0123456789012345678901234567890123456789 0123456789012345678901234567890123456789", + " Second row", + " First rowSecond row" ] let outputs = [ - + "0123456789012345678901234567890123456789\n0123456789012345678901234567890123456789", + "0123456789 0123456789 0123456789 0123456\n789 0123456789 0123456789 0123456789", + "0123456789012345678901234567890123456789\n0123456789012345678901234567890123456789", + "\nSecond row", + "First row\nSecond row" ] /* @@ -31,11 +39,17 @@ Lorem ipsumos dolor sit amet consectetur even though there is a space before the a in adipisicing */ function f(str) { - + str.trim(); + if (str.length > 40) { + var firStr = str.slice(0, 40); + var secStr = str.slice(40); + var newStr = [firStr.trim(), "\n", secStr.trim()].join(""); + return newStr; + } } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); + if (i > inputs.length) throw new Error("You do not have enough test cases"); var expected = outputs[i]; var actual = f(inputs[i]); assert.deepEqual(actual, expected); From 74352d4fc8d15778bcefa43402cf314f8f09c263 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 22:00:09 -0500 Subject: [PATCH 14/19] Problem15.js was solved --- problems/problem15.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/problems/problem15.js b/problems/problem15.js index eb49b73..147259e 100644 --- a/problems/problem15.js +++ b/problems/problem15.js @@ -2,11 +2,19 @@ var assert = require('assert'); // we need 5 test cases. let inputs = [ - + "01234567890123456789012345678901234567890123456789012345678901234567890123456789", + "0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789", + "0123456789012345678901234567890123456789 0123456789012345678901234567890123456789", + " Second row", + " First rowSecond row" ] let outputs = [ - + "0123456789012345678901234567890123456789\n0123456789012345678901234567890123456789", + "0123456789 0123456789 0123456789 0123456\n789 0123456789 0123456789 0123456789", + "0123456789012345678901234567890123456789\n0123456789012345678901234567890123456789", + "\nSecond row", + "First row\nSecond row" ] /* @@ -31,11 +39,17 @@ Lorem ipsumos dolor sit amet consectetur even though there is a space before the a in adipisicing */ function f(str) { - + str.trim(); + if (str.length > 40) { + var firStr = str.slice(0, 40); + var secStr = str.slice(40); + var newStr = [firStr.trim(), "\n", secStr.trim()].join(""); + return newStr; + } } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); + if (i > inputs.length) throw new Error("You do not have enough test cases"); var expected = outputs[i]; var actual = f(inputs[i]); assert.deepEqual(actual, expected); From b56bef58d9b275a65d90201753cac0046594fc8c Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 22:04:13 -0500 Subject: [PATCH 15/19] Problem16.js is solved --- problems/problem16.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/problems/problem16.js b/problems/problem16.js index 9880f09..d42ce85 100644 --- a/problems/problem16.js +++ b/problems/problem16.js @@ -10,7 +10,7 @@ let inputs = [ ] let outputs = [ - 1, + 01, 5, 9, 18, @@ -18,7 +18,7 @@ let outputs = [ ] function f(digit) { - return digit%10 + (digit - digit % 10) / 10; + return digit % 10 + (digit - digit % 10) / 10; } function runTest(i) { From 85198ee37ac66804485abeb7420f9bee544b8600 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 22:54:46 -0500 Subject: [PATCH 16/19] Problem12.js is solved --- problems/problem12.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/problems/problem12.js b/problems/problem12.js index e0b786b..f7260b3 100644 --- a/problems/problem12.js +++ b/problems/problem12.js @@ -5,7 +5,7 @@ let inputs = [ [[1, 2, 3], [4, 5, 6]], [[1, 2, 3, 4, 5, 6], [4, 5, 6]], [[1, 2, 3], [1, 2, 3, 4, 5, 6]], - ["hi", [1, 2, 3]], + [[1, 3, 4], [1, 2, 3]], [[1, 2, 3, 5], [2, 4, 5, 6]] ] @@ -13,7 +13,7 @@ let outputs = [ [1, 2, 3, 4, 5, 6], [1, 2, 3], [4, 5, 6], - undefined, + [4, 2], [1, 3, 4, 6] ] @@ -28,11 +28,8 @@ uniqueElements([1,2,3], [1,2,3]); // [] uniqueElements(2,3); // undefined, not arrays */ function f(arr) { - Array.isArray(arr[0]) && Array.isArray(arr[1]) - - concat(array) - - filter(e =>) + var newArr = !Array.isArray(arr[0]) && !Array.isArray(arr[1]) ? undefined : arr[0].concat(arr[1]).filter(e => arr[0].includes(e) && !arr[1].includes(e) || !arr[0].includes(e) && arr[1].includes(e)); + return newArr; } function runTest(i) { From 8a9d71909cdb95cce3a7bad6252484890dba6858 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Wed, 10 Jan 2018 23:04:26 -0500 Subject: [PATCH 17/19] Every problem solved --- problems/problem1.js | 2 ++ problems/problem10.js | 2 ++ problems/problem11.js | 2 ++ problems/problem12.js | 2 ++ problems/problem13.js | 2 ++ problems/problem14.js | 2 ++ problems/problem15.js | 2 ++ problems/problem16.js | 1 + problems/problem2.js | 2 ++ problems/problem3.js | 2 ++ problems/problem4.js | 2 ++ problems/problem5.js | 6 ++++-- problems/problem6.js | 2 ++ problems/problem7.js | 2 ++ problems/problem8.js | 18 ++++++++++-------- problems/problem9.js | 2 ++ 16 files changed, 41 insertions(+), 10 deletions(-) diff --git a/problems/problem1.js b/problems/problem1.js index 96c2d65..09ddb0f 100644 --- a/problems/problem1.js +++ b/problems/problem1.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. I provided 1 input diff --git a/problems/problem10.js b/problems/problem10.js index 013c379..8f5801c 100644 --- a/problems/problem10.js +++ b/problems/problem10.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. diff --git a/problems/problem11.js b/problems/problem11.js index 1478453..9cd5357 100644 --- a/problems/problem11.js +++ b/problems/problem11.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. diff --git a/problems/problem12.js b/problems/problem12.js index f7260b3..48c0855 100644 --- a/problems/problem12.js +++ b/problems/problem12.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. diff --git a/problems/problem13.js b/problems/problem13.js index c7376d3..2f4e46f 100644 --- a/problems/problem13.js +++ b/problems/problem13.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. diff --git a/problems/problem14.js b/problems/problem14.js index 147259e..84771a5 100644 --- a/problems/problem14.js +++ b/problems/problem14.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. diff --git a/problems/problem15.js b/problems/problem15.js index 147259e..84771a5 100644 --- a/problems/problem15.js +++ b/problems/problem15.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. diff --git a/problems/problem16.js b/problems/problem16.js index d42ce85..e043246 100644 --- a/problems/problem16.js +++ b/problems/problem16.js @@ -1,3 +1,4 @@ +// SOLVED! var assert = require('assert'); diff --git a/problems/problem2.js b/problems/problem2.js index c15dd60..46c19a7 100644 --- a/problems/problem2.js +++ b/problems/problem2.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. diff --git a/problems/problem3.js b/problems/problem3.js index fb5c8f4..4f34660 100644 --- a/problems/problem3.js +++ b/problems/problem3.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 7 test cases. I've provided 2. diff --git a/problems/problem4.js b/problems/problem4.js index 0056263..3cf5f4e 100644 --- a/problems/problem4.js +++ b/problems/problem4.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 8 test cases. I've provided the first 2 diff --git a/problems/problem5.js b/problems/problem5.js index 5e24b59..4948363 100644 --- a/problems/problem5.js +++ b/problems/problem5.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. @@ -21,8 +23,8 @@ let outputs = [ Make this function return the product of the two numbers that are passed to it. If one of the numbers is not passed, or if anything other than numbers are passed, return undefined. */ function f(x) { - if ((!isNaN(x[0]) && !isNaN(x[1])) && (x[0] !== ("" || '') && x[1] !== ("" || ''))){ - var result = x[0]*x[1]; + if ((!isNaN(x[0]) && !isNaN(x[1])) && (x[0] !== ("" || '') && x[1] !== ("" || ''))) { + var result = x[0] * x[1]; return result; } return undefined; diff --git a/problems/problem6.js b/problems/problem6.js index 1d6e394..bf6d377 100644 --- a/problems/problem6.js +++ b/problems/problem6.js @@ -1,3 +1,5 @@ +// SOLVED! + // pro tip: use nodemon instead of node var assert = require('assert'); diff --git a/problems/problem7.js b/problems/problem7.js index b489f98..4556e7c 100644 --- a/problems/problem7.js +++ b/problems/problem7.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 7 test cases. diff --git a/problems/problem8.js b/problems/problem8.js index cc7dc28..31b65ce 100644 --- a/problems/problem8.js +++ b/problems/problem8.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. @@ -10,11 +12,11 @@ let inputs = [ ] let outputs = [ - "racecar", - "rettub", - "retupmoc", - "raj", - "mottob" + "racecar", + "rettub", + "retupmoc", + "raj", + "mottob" ] /* @@ -24,15 +26,15 @@ You must use a for loop for this exercise. function f(str) { var newStr = str.split(''); var newWord = []; - for(var i = 0; i<=str.length; ++i){ + for (var i = 0; i <= str.length; ++i) { newWord.push(newStr[str.length - i]); } - + return newWord.join(''); } function runTest(i) { - if(i > inputs.length) throw new Error("You do not have enough test cases"); + if (i > inputs.length) throw new Error("You do not have enough test cases"); var expected = outputs[i]; var actual = f(inputs[i]); assert.deepEqual(actual, expected); diff --git a/problems/problem9.js b/problems/problem9.js index 0f34d6e..4c32f6f 100644 --- a/problems/problem9.js +++ b/problems/problem9.js @@ -1,3 +1,5 @@ +// SOLVED! + var assert = require('assert'); // we need 5 test cases. From 38075a223fb327998beeeaa666d7e3304ebe5404 Mon Sep 17 00:00:00 2001 From: Archer143 Date: Mon, 15 Jan 2018 17:23:48 -0500 Subject: [PATCH 18/19] Commit --- problems/.vscode/launch.json | 2 +- problems/problem14.js | 36 +++++++++++++++++++++++-------- problems/problem15.js | 42 ++++++++++++++++++++++++++++-------- 3 files changed, 61 insertions(+), 19 deletions(-) diff --git a/problems/.vscode/launch.json b/problems/.vscode/launch.json index 7cca2fa..a053d23 100644 --- a/problems/.vscode/launch.json +++ b/problems/.vscode/launch.json @@ -8,7 +8,7 @@ "type": "node", "request": "launch", "name": "Launch Program", - "program": "${workspaceFolder}/problem6.js" + "program": "${file}" } ] } \ No newline at end of file diff --git a/problems/problem14.js b/problems/problem14.js index 84771a5..9865732 100644 --- a/problems/problem14.js +++ b/problems/problem14.js @@ -8,15 +8,15 @@ let inputs = [ "0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789", "0123456789012345678901234567890123456789 0123456789012345678901234567890123456789", " Second row", - " First rowSecond row" + " First row and Second row" ] let outputs = [ "0123456789012345678901234567890123456789\n0123456789012345678901234567890123456789", "0123456789 0123456789 0123456789 0123456\n789 0123456789 0123456789 0123456789", "0123456789012345678901234567890123456789\n0123456789012345678901234567890123456789", - "\nSecond row", - "First row\nSecond row" + "Second row", + "First row and Second row" ] /* @@ -41,13 +41,31 @@ Lorem ipsumos dolor sit amet consectetur even though there is a space before the a in adipisicing */ function f(str) { - str.trim(); - if (str.length > 40) { - var firStr = str.slice(0, 40); - var secStr = str.slice(40); - var newStr = [firStr.trim(), "\n", secStr.trim()].join(""); - return newStr; + console.log("\nFunction Start\n" + str + "\n"); + var newStr = str.trim(); + console.log(newStr); + var arr = []; + var endLoop = true; + var i = 0; + + if (newStr.length > 40) { + while (endLoop === true) { + console.log("LOOP"); + if (newStr.length > 40 * i) { + arr[i] = newStr.slice(40 * i, 40 * (i + 1)).trimLeft(); + console.log(arr[i]); + } + + else { + endLoop = false; + } + ++i; + + if (str.length === 40 * i) endLoop = false; + } + return arr.join("\n"); } + return newStr; } function runTest(i) { diff --git a/problems/problem15.js b/problems/problem15.js index 84771a5..7ecbe41 100644 --- a/problems/problem15.js +++ b/problems/problem15.js @@ -8,15 +8,15 @@ let inputs = [ "0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789", "0123456789012345678901234567890123456789 0123456789012345678901234567890123456789", " Second row", - " First rowSecond row" + " First row and Second row" ] let outputs = [ "0123456789012345678901234567890123456789\n0123456789012345678901234567890123456789", "0123456789 0123456789 0123456789 0123456\n789 0123456789 0123456789 0123456789", "0123456789012345678901234567890123456789\n0123456789012345678901234567890123456789", - "\nSecond row", - "First row\nSecond row" + "Second row", + "First row and Second row" ] /* @@ -41,13 +41,37 @@ Lorem ipsumos dolor sit amet consectetur even though there is a space before the a in adipisicing */ function f(str) { - str.trim(); - if (str.length > 40) { - var firStr = str.slice(0, 40); - var secStr = str.slice(40); - var newStr = [firStr.trim(), "\n", secStr.trim()].join(""); - return newStr; + console.log("\nFunction Start\n" + str + "\n"); + var newStr = str.trim(); + console.log(newStr); + var arr = []; + var endLoop = true; + var i = 0; + console.log("loop starts"); + if (newStr.length > 40) { + while (endLoop === true) { + console.log("LOOP"); + if (newStr.length > 40 * i) { + arr[i] = newStr.slice(40 * i, 40 * (i + 1)).trimLeft(); + console.log(arr[i]); + + if(arr[i].charAt(0) === " "){ + arr[i] = newStr.slice((40 * i)+1, (40 * (i + 1))+1).trimLeft(); + console.log("modify"); + console.log(arr[i]); + } + } + + else { + endLoop = false; + } + ++i; + + if (str.length === 40 * i) endLoop = false; + } + return arr.join("\n"); } + return newStr; } function runTest(i) { From d2a66bd199264a5c23c8adcded714f06ac191bbe Mon Sep 17 00:00:00 2001 From: Archer143 Date: Mon, 15 Jan 2018 19:41:56 -0500 Subject: [PATCH 19/19] Solved --- problems/.vscode/launch.json | 2 +- problems/problem1.js | 2 +- problems/problem10.js | 2 +- problems/problem11.js | 2 +- problems/problem12.js | 2 +- problems/problem13.js | 2 +- problems/problem14.js | 47 +++++++++++++++----------------- problems/problem15.js | 53 +++++++++++++++--------------------- problems/problem16.js | 2 +- problems/problem2.js | 2 +- problems/problem3.js | 2 +- problems/problem4.js | 2 +- problems/problem5.js | 2 +- problems/problem6.js | 2 +- problems/problem7.js | 2 +- problems/problem8.js | 2 +- problems/problem9.js | 2 +- 17 files changed, 59 insertions(+), 71 deletions(-) diff --git a/problems/.vscode/launch.json b/problems/.vscode/launch.json index a053d23..27d3060 100644 --- a/problems/.vscode/launch.json +++ b/problems/.vscode/launch.json @@ -1,5 +1,5 @@ { - // Use IntelliSense to learn about possible attributes. + // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", diff --git a/problems/problem1.js b/problems/problem1.js index 09ddb0f..95ef6f6 100644 --- a/problems/problem1.js +++ b/problems/problem1.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem10.js b/problems/problem10.js index 8f5801c..d5b927c 100644 --- a/problems/problem10.js +++ b/problems/problem10.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem11.js b/problems/problem11.js index 9cd5357..2ff5c84 100644 --- a/problems/problem11.js +++ b/problems/problem11.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem12.js b/problems/problem12.js index 48c0855..513da3c 100644 --- a/problems/problem12.js +++ b/problems/problem12.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem13.js b/problems/problem13.js index 2f4e46f..743b57b 100644 --- a/problems/problem13.js +++ b/problems/problem13.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem14.js b/problems/problem14.js index 9865732..9016c91 100644 --- a/problems/problem14.js +++ b/problems/problem14.js @@ -8,7 +8,7 @@ let inputs = [ "0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789", "0123456789012345678901234567890123456789 0123456789012345678901234567890123456789", " Second row", - " First row and Second row" + "0123456789012345678901234567890123456789 9" ] let outputs = [ @@ -16,7 +16,7 @@ let outputs = [ "0123456789 0123456789 0123456789 0123456\n789 0123456789 0123456789 0123456789", "0123456789012345678901234567890123456789\n0123456789012345678901234567890123456789", "Second row", - "First row and Second row" + "0123456789012345678901234567890123456789\n9" ] /* @@ -40,32 +40,30 @@ Lorem ipsumos dolor sit amet consectetur even though there is a space before the a in adipisicing */ + +// 1- Verifies is loop is necessary +// 2- Loop to change line at every 40 characters +// 3- Verifies if there is more text modify +// 4- Verifies if the first character of a new line would be an empty character +// 5- If that happens, it simply skips it and verifies the next character +// 6- No risk of this never ending or going to the end of the string because of str.trim() at beginning +// 7- Extracts 40 characters strating from the first index and then places the extracted string into the array's next position + function f(str) { - console.log("\nFunction Start\n" + str + "\n"); var newStr = str.trim(); - console.log(newStr); + if (newStr.length < 40) return newStr; // *1 + var i = 0; + var j = 0; var arr = []; var endLoop = true; - var i = 0; - - if (newStr.length > 40) { - while (endLoop === true) { - console.log("LOOP"); - if (newStr.length > 40 * i) { - arr[i] = newStr.slice(40 * i, 40 * (i + 1)).trimLeft(); - console.log(arr[i]); - } - - else { - endLoop = false; - } - ++i; - - if (str.length === 40 * i) endLoop = false; + while (endLoop === true) { // *2 + if (newStr.length > (40 * i) + j) { // *3 + if (newStr.charAt((40 * i) + j) === " ") while (newStr.charAt((40 * i) + j) === " ")++j; // *4*5*6 + arr[i] = newStr.slice((40 * i) + j, (40 * (i + 1)) + j); // *7 } - return arr.join("\n"); - } - return newStr; + else endLoop = false; + ++i; + } return arr.join("\n"); } function runTest(i) { @@ -79,5 +77,4 @@ runTest(0); runTest(1); runTest(2); runTest(3); -runTest(4); - +runTest(4); \ No newline at end of file diff --git a/problems/problem15.js b/problems/problem15.js index 7ecbe41..9016c91 100644 --- a/problems/problem15.js +++ b/problems/problem15.js @@ -8,7 +8,7 @@ let inputs = [ "0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789", "0123456789012345678901234567890123456789 0123456789012345678901234567890123456789", " Second row", - " First row and Second row" + "0123456789012345678901234567890123456789 9" ] let outputs = [ @@ -16,7 +16,7 @@ let outputs = [ "0123456789 0123456789 0123456789 0123456\n789 0123456789 0123456789 0123456789", "0123456789012345678901234567890123456789\n0123456789012345678901234567890123456789", "Second row", - "First row and Second row" + "0123456789012345678901234567890123456789\n9" ] /* @@ -40,38 +40,30 @@ Lorem ipsumos dolor sit amet consectetur even though there is a space before the a in adipisicing */ + +// 1- Verifies is loop is necessary +// 2- Loop to change line at every 40 characters +// 3- Verifies if there is more text modify +// 4- Verifies if the first character of a new line would be an empty character +// 5- If that happens, it simply skips it and verifies the next character +// 6- No risk of this never ending or going to the end of the string because of str.trim() at beginning +// 7- Extracts 40 characters strating from the first index and then places the extracted string into the array's next position + function f(str) { - console.log("\nFunction Start\n" + str + "\n"); var newStr = str.trim(); - console.log(newStr); + if (newStr.length < 40) return newStr; // *1 + var i = 0; + var j = 0; var arr = []; var endLoop = true; - var i = 0; - console.log("loop starts"); - if (newStr.length > 40) { - while (endLoop === true) { - console.log("LOOP"); - if (newStr.length > 40 * i) { - arr[i] = newStr.slice(40 * i, 40 * (i + 1)).trimLeft(); - console.log(arr[i]); - - if(arr[i].charAt(0) === " "){ - arr[i] = newStr.slice((40 * i)+1, (40 * (i + 1))+1).trimLeft(); - console.log("modify"); - console.log(arr[i]); - } - } - - else { - endLoop = false; - } - ++i; - - if (str.length === 40 * i) endLoop = false; + while (endLoop === true) { // *2 + if (newStr.length > (40 * i) + j) { // *3 + if (newStr.charAt((40 * i) + j) === " ") while (newStr.charAt((40 * i) + j) === " ")++j; // *4*5*6 + arr[i] = newStr.slice((40 * i) + j, (40 * (i + 1)) + j); // *7 } - return arr.join("\n"); - } - return newStr; + else endLoop = false; + ++i; + } return arr.join("\n"); } function runTest(i) { @@ -85,5 +77,4 @@ runTest(0); runTest(1); runTest(2); runTest(3); -runTest(4); - +runTest(4); \ No newline at end of file diff --git a/problems/problem16.js b/problems/problem16.js index e043246..0a3d910 100644 --- a/problems/problem16.js +++ b/problems/problem16.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem2.js b/problems/problem2.js index 46c19a7..537831b 100644 --- a/problems/problem2.js +++ b/problems/problem2.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem3.js b/problems/problem3.js index 4f34660..5db2f60 100644 --- a/problems/problem3.js +++ b/problems/problem3.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem4.js b/problems/problem4.js index 3cf5f4e..a9b8e70 100644 --- a/problems/problem4.js +++ b/problems/problem4.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem5.js b/problems/problem5.js index 4948363..b5307e4 100644 --- a/problems/problem5.js +++ b/problems/problem5.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem6.js b/problems/problem6.js index bf6d377..ee09b59 100644 --- a/problems/problem6.js +++ b/problems/problem6.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! // pro tip: use nodemon instead of node var assert = require('assert'); diff --git a/problems/problem7.js b/problems/problem7.js index 4556e7c..31ee8e1 100644 --- a/problems/problem7.js +++ b/problems/problem7.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem8.js b/problems/problem8.js index 31b65ce..0e095f0 100644 --- a/problems/problem8.js +++ b/problems/problem8.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert'); diff --git a/problems/problem9.js b/problems/problem9.js index 4c32f6f..cfc875a 100644 --- a/problems/problem9.js +++ b/problems/problem9.js @@ -1,4 +1,4 @@ -// SOLVED! +// SOLVED! var assert = require('assert');