-
Notifications
You must be signed in to change notification settings - Fork 0
Tues exercism #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: exorcism
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -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; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,60 +8,60 @@ 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!'); | ||
| }); | ||
|
|
||
| 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!'); | ||
|
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. I'm curious what the intention of this test and the special characters test above it are. Both of those tests have ordinary capitalized letters followed by exclamation marks, which should match the RegExp regardless of whether the special characters match. I know you didn't write it, I'm just not sure that it's testing anything different than the other cases and wanted to point that out. 😋 |
||
| expect(result).toEqual('Whoa, chill out!'); | ||
| }); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| var bracket = function(input) { | ||
| //define what ending bracket should be if the beginning is found | ||
| }; | ||
|
|
||
|
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. You should try to keep incomplete placeholders like this out of commits for complete tests, that way you have more freedom to cherry pick commits later or reorder them during a rebase without ending up with files getting reverted to a broken state. Personally I try to make a separate commit for each change (ex: secret handshake would be a different commit from bob, and bob's commit would never have changes to secret handshake's files) but that's just one way of keeping git stuff organized. |
||
|
|
||
| module.exports = bracket; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| var SecretHandshake = function(input) { | ||
| if (typeof input !== 'number') { | ||
| throw new Error('Handshake must be a number') | ||
| } | ||
|
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. 👍 |
||
| this.number = input | ||
| }; | ||
|
|
||
| SecretHandshake.prototype.commands = function() { | ||
| //convert this.number to binary | ||
| let number = this.number | ||
| let binaryArray = [] | ||
| let handshakeArray = [] | ||
|
|
||
| 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) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| for (let key in shakes) { | ||
| if (binaryNumber >= shakes[key]) { | ||
| pushHandshakes(key) | ||
| binaryNumber -= shakes[key] | ||
| } | ||
| } | ||
|
|
||
| return handshakeArray | ||
|
|
||
| }; | ||
|
|
||
| module.exports = SecretHandshake; | ||
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.
Good use of RegExp, especially the lookahead 👍