From 0c502dd8e70eb0363a8e3a3cc7503e8b283edcf1 Mon Sep 17 00:00:00 2001 From: Breyana Scales Date: Tue, 28 Feb 2017 13:18:38 -0800 Subject: [PATCH 1/3] work in progress secret handshake --- exercism/bracket-push/bracket-push.js | 6 ++++ exercism/secret-handshake/secret-handshake.js | 32 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 exercism/bracket-push/bracket-push.js create mode 100644 exercism/secret-handshake/secret-handshake.js diff --git a/exercism/bracket-push/bracket-push.js b/exercism/bracket-push/bracket-push.js new file mode 100644 index 0000000..379a1cb --- /dev/null +++ b/exercism/bracket-push/bracket-push.js @@ -0,0 +1,6 @@ +var bracket = function(input) { + //define what ending bracket should be if the beginning is found +}; + + +module.exports = bracket; diff --git a/exercism/secret-handshake/secret-handshake.js b/exercism/secret-handshake/secret-handshake.js new file mode 100644 index 0000000..369e835 --- /dev/null +++ b/exercism/secret-handshake/secret-handshake.js @@ -0,0 +1,32 @@ +var SecretHandshake = function(input) { + if (typeof input !== 'number') { + throw new Error('Handshake must be a number') + } + this.number = input +}; + +SecretHandshake.prototype.commands = function() { + //convert this.number to binary + let number = this.number + let binaryArray = [] + + while (number >= 1) { + converted.unshift(number%2) + number = Math.floor(number/2) + } + + let binaryNumber = parseInt(binaryArray.join('')) + // + + const shakes = { + 1: "wink" + 10: "double blink" + 100: "close your eyes" + 1000: "jump" + 10000: function() { + //reverse order of operations + } + } +}; + +module.exports = SecretHandshake; From 5812bcbc9084097d7a3deefdc4d7a30561d821e9 Mon Sep 17 00:00:00 2001 From: Breyana Scales Date: Tue, 28 Feb 2017 16:04:27 -0800 Subject: [PATCH 2/3] Secret Handshake --- exercism/secret-handshake/secret-handshake.js | 54 +++++++++++++------ .../secret-handshake/secret-handshake.spec.js | 14 ++--- 2 files changed, 45 insertions(+), 23 deletions(-) diff --git a/exercism/secret-handshake/secret-handshake.js b/exercism/secret-handshake/secret-handshake.js index 369e835..d029b64 100644 --- a/exercism/secret-handshake/secret-handshake.js +++ b/exercism/secret-handshake/secret-handshake.js @@ -7,26 +7,48 @@ var SecretHandshake = function(input) { SecretHandshake.prototype.commands = function() { //convert this.number to binary - let number = this.number - let binaryArray = [] +let number = this.number +let binaryArray = [] +let handshakeArray = [] - while (number >= 1) { - converted.unshift(number%2) - number = Math.floor(number/2) +while (number >= 1) { + binaryArray.unshift(number%2) + number = Math.floor(number/2) +} + +let binaryNumber = parseInt(binaryArray.join('')) + +const shakes = { + "jump": 1000, + "close your eyes": 100, + "double blink": 10, + "wink": 1 + // 10000: function() { + // //reverse order of operations + // } +} + +if (binaryNumber >= 10000) { + var pushHandshakes = function(input) { + handshakeArray.push(input) + } + binaryNumber -= 10000 +} else { + var pushHandshakes = function(input) { + handshakeArray.unshift(input) } - let binaryNumber = parseInt(binaryArray.join('')) - // - - const shakes = { - 1: "wink" - 10: "double blink" - 100: "close your eyes" - 1000: "jump" - 10000: function() { - //reverse order of operations - } +} + +for (let key in shakes) { + if (binaryNumber >= shakes[key]) { + pushHandshakes(key) + binaryNumber -= shakes[key] } +} + +return handshakeArray + }; module.exports = SecretHandshake; diff --git a/exercism/secret-handshake/secret-handshake.spec.js b/exercism/secret-handshake/secret-handshake.spec.js index dd9b0de..cea1d32 100644 --- a/exercism/secret-handshake/secret-handshake.spec.js +++ b/exercism/secret-handshake/secret-handshake.spec.js @@ -6,37 +6,37 @@ describe('Secret Handshake', function() { expect(handshake.commands()).toEqual(['wink']); }); - xit('10 is a double blink', function() { + it('10 is a double blink', function() { var handshake = new SecretHandshake(2); expect(handshake.commands()).toEqual(['double blink']); }); - xit('100 is close your eyes', function() { + it('100 is close your eyes', function() { var handshake = new SecretHandshake(4); expect(handshake.commands()).toEqual(['close your eyes']); }); - xit('1000 is jump', function() { + it('1000 is jump', function() { var handshake = new SecretHandshake(8); expect(handshake.commands()).toEqual(['jump']); }); - xit('11 is wink and double blink', function() { + it('11 is wink and double blink', function() { var handshake = new SecretHandshake(3); expect(handshake.commands()).toEqual(['wink','double blink']); }); - xit('10011 is double blink and wink', function() { + it('10011 is double blink and wink', function() { var handshake = new SecretHandshake(19); expect(handshake.commands()).toEqual(['double blink','wink']); }); - xit('11111 is jump, close your eyes, double blink, and wink', function() { + it('11111 is jump, close your eyes, double blink, and wink', function() { var handshake = new SecretHandshake(31); expect(handshake.commands()).toEqual(['jump','close your eyes','double blink','wink']); }); - xit('text is an invalid secret handshake', function() { + it('text is an invalid secret handshake', function() { expect( function () { var handshake = new SecretHandshake('piggies'); }).toThrow(new Error('Handshake must be a number')); From 7f74f30acf6368cdfe8c591880cbaebca007745a Mon Sep 17 00:00:00 2001 From: Breyana Scales Date: Tue, 28 Feb 2017 16:44:02 -0800 Subject: [PATCH 3/3] completed Bob function --- exercism/bob/bob.js | 15 +++++++++++++++ exercism/bob/bob.spec.js | 24 ++++++++++++------------ team_practice.md | 8 ++++---- 3 files changed, 31 insertions(+), 16 deletions(-) create mode 100644 exercism/bob/bob.js diff --git a/exercism/bob/bob.js b/exercism/bob/bob.js new file mode 100644 index 0000000..3f90cfe --- /dev/null +++ b/exercism/bob/bob.js @@ -0,0 +1,15 @@ +var Bob = function() {}; + +Bob.prototype.hey = function(what) { + if (/([A-Z]+\s){2,}|[A-Z](?=!)/.test(what)) { + return 'Whoa, chill out!' + } else if (/(.+)(?=\?)/.test(what)) { + return 'Sure.' + } else if (!what) { + return 'Fine. Be that way!' + } else { + return 'Whatever.' + } +}; + +module.exports = Bob; diff --git a/exercism/bob/bob.spec.js b/exercism/bob/bob.spec.js index c87a1cc..d4e9577 100644 --- a/exercism/bob/bob.spec.js +++ b/exercism/bob/bob.spec.js @@ -8,47 +8,47 @@ describe('Bob', function() { expect(result).toEqual('Whatever.'); }); - xit('shouting', function() { + it('shouting', function() { var result = bob.hey('WATCH OUT!'); expect(result).toEqual('Whoa, chill out!'); }); - xit('asking a question', function() { + it('asking a question', function() { var result = bob.hey('Does this cryogenic chamber make me look fat?'); expect(result).toEqual('Sure.'); }); - xit('talking forcefully', function() { + it('talking forcefully', function() { var result = bob.hey('Let\'s go make out behind the gym!'); expect(result).toEqual('Whatever.'); }); - xit('using acronyms in regular speech', function() { + it('using acronyms in regular speech', function() { var result = bob.hey('It\'s OK if you don\'t want to go to the DMV.'); expect(result).toEqual('Whatever.'); }); - xit('forceful questions', function() { + it('forceful questions', function() { var result = bob.hey('WHAT THE HELL WERE YOU THINKING?'); expect(result).toEqual('Whoa, chill out!'); }); - xit('shouting numbers', function() { + it('shouting numbers', function() { var result = bob.hey('1, 2, 3 GO!'); expect(result).toEqual('Whoa, chill out!'); }); - xit('only numbers', function() { + it('only numbers', function() { var result = bob.hey('1, 2, 3'); expect(result).toEqual('Whatever.'); }); - xit('question with only numbers', function() { + it('question with only numbers', function() { var result = bob.hey('4?'); expect(result).toEqual('Sure.'); }); - xit('shouting with special characters', function() { + it('shouting with special characters', function() { var result = bob.hey('ZOMG THE %^*@#$(*^ ZOMBIES ARE COMING!!11!!1!'); expect(result).toEqual('Whoa, chill out!'); }); @@ -56,12 +56,12 @@ describe('Bob', function() { xit('shouting with umlauts', function() { /* NOTE: \xc4 = Ä \xe4 = ä - \xdc = Ü + \xdc = Ü \xfc = ü "\xfcML\xe4\xdcTS" === "üMLäÜTS" */ - - var result = bob.hey('\xdcML\xc4\xdcTS!'); + + var result = bob.hey('\xdcML\xc4\xdcTS!'); expect(result).toEqual('Whoa, chill out!'); }); diff --git a/team_practice.md b/team_practice.md index d97200c..46877df 100644 --- a/team_practice.md +++ b/team_practice.md @@ -11,8 +11,8 @@ Exercism provides a number of practice problems along with unit tests to ensure ### Day 1 - Exercism -- [ ] Solve `/exercism/hamming` -- [ ] Solve `/exercism/diamond` +- [x] Solve `/exercism/hamming` +- [x] Solve `/exercism/diamond` - [ ] Solve `/exercism/bracket-push` - [ ] Solve `/exercism/ocr-numbers` - [ ] Solve `/exercism/bowling` @@ -34,12 +34,12 @@ Exercism provides a number of practice problems along with unit tests to ensure ### Day 2 - Exercism -- [ ] Solve `/exercism/secret-handshake` +- [x] Solve `/exercism/secret-handshake` - [ ] Solve `/exercism/wordy` - [ ] Solve `/exercism/largest-series-product` - [ ] Solve `/exercism/robot-simulator` - [ ] Solve `/exercism/rna-transcription` -- [ ] Solve `/exercism/bob` +- [x] Solve `/exercism/bob` #### Stretch