Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions exercism/bob/bob.js
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)) {

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 👍

return 'Whoa, chill out!'
} else if (/(.+)(?=\?)/.test(what)) {
return 'Sure.'
} else if (!what) {
return 'Fine. Be that way!'
} else {
return 'Whatever.'
}
};

module.exports = Bob;
24 changes: 12 additions & 12 deletions exercism/bob/bob.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!');

Choose a reason for hiding this comment

The 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!');
});

Expand Down
6 changes: 6 additions & 0 deletions exercism/bracket-push/bracket-push.js
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
};

Choose a reason for hiding this comment

The 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;
54 changes: 54 additions & 0 deletions exercism/secret-handshake/secret-handshake.js
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')
}

Choose a reason for hiding this comment

The 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;
14 changes: 7 additions & 7 deletions exercism/secret-handshake/secret-handshake.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
8 changes: 4 additions & 4 deletions team_practice.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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
Expand Down