Skip to content

Commit 90bfcd7

Browse files
author
Chris Bee
committed
practice session
1 parent a28f4b9 commit 90bfcd7

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

balancedParens/balancedParens.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* write a function that takes a string of text and returns true if
3+
* the parentheses are balanced and false otherwise.
4+
*
5+
* Example:
6+
* balancedParens('('); // false
7+
* balancedParens('()'); // true
8+
* balancedParens(')('); // false
9+
* balancedParens('(())'); // true
10+
*
11+
* Step 2:
12+
* make your solution work for all types of brackets
13+
*
14+
* Example:
15+
* balancedParens('[](){}'); // true
16+
* balancedParens('[({})]'); // true
17+
* balancedParens('[(]{)}'); // false
18+
*
19+
* Step 3:
20+
* ignore non-bracket characters
21+
* balancedParens(' var wow = { yo: thisIsAwesome() }'); // true
22+
* balancedParens(' var hubble = function() { telescopes.awesome();'); // false
23+
*
24+
*
25+
*/
26+
var balancedParens = function(input){
27+
28+
var arr = [];
29+
var pairs = {};
30+
pairs["["] = "]";
31+
pairs["{"] = "}";
32+
pairs["("] = ")";
33+
34+
for (var i = 0; i < input.length; i++) {
35+
if(input[i] === '[' || input[i] === '(' || input[i] === '{') {
36+
arr.push(input[i]);
37+
}
38+
if(input[i] === ']' || input[i] === ')' || input[i] === '}') {
39+
var val = arr.pop();
40+
if(pairs[val] !== input[i]){
41+
return false;
42+
}
43+
}
44+
}
45+
46+
if (arr.length > 0) {
47+
return false;
48+
}
49+
50+
return true;
51+
52+
};
53+
54+
55+
console.log(balancedParens('(')); // false
56+
console.log(balancedParens('()')); // true
57+
console.log(balancedParens(')(')); // false
58+
console.log(balancedParens('(())')); // true
59+

blackjack/blackjack.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//Create a blackjack game
2+
3+
/*
4+
Rules
5+
N players play against dealer
6+
Total of cards must be below 21
7+
Goal is to beat dealer score without going over 21
8+
Players can hit or stand
9+
Aces are special - 1 or 11
10+
11+
12+
Players
13+
- Dealer true
14+
- score 0
15+
- cards []
16+
- actions: hit(), stand()
17+
-- if bust, score = -1
18+
19+
Deck
20+
- cards []
21+
- shuffle
22+
23+
Game
24+
- Players []
25+
- Start game, deal cards
26+
- End game, determine winner
27+
28+
29+
*/

0 commit comments

Comments
 (0)