-
Notifications
You must be signed in to change notification settings - Fork 20
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
Shelly #18
Open
shellytang
wants to merge
8
commits into
codefellows-seattle-javascript-401d15:master
Choose a base branch
from
shellytang:shelly
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Shelly #18
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
1b09318
lab steup
shellytang d0b9e5f
created modules
shellytang cfcebcc
reorg lib files. working on balanced brackets
shellytang 57f7ab2
fixed error conditions
shellytang 787e385
refactored into single stack
shellytang 11ae4bd
tests
shellytang d8dacd8
removed console logs
shellytang 5fa9afa
forgot to push up eslintrc
shellytang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"rules": { | ||
"quotes": ["error", "single", { "allowTemplateLiterals": true }], | ||
"comma-dangle": ["error", "always-multiline"], | ||
"no-console": "off", | ||
"indent": [ "error", 2 ], | ||
"semi": ["error", "always"] | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true, | ||
"mocha": true, | ||
"jasmine": true | ||
}, | ||
"globals": { | ||
"__API_URI__": false, | ||
"__DEBUG__": false | ||
}, | ||
"ecmaFeatures": { | ||
"modules": true, | ||
"experimentalObjectRestSpread": true, | ||
"impliedStrict": true | ||
}, | ||
"extends": "eslint:recommended" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# ignore db directorys | ||
db | ||
|
||
# Created by https://www.gitignore.io/api/linux,node,osx,vim | ||
|
||
### Linux ### | ||
*~ | ||
|
||
# temporary files which can be created if a process still has a handle open of a deleted file | ||
.fuse_hidden* | ||
|
||
# KDE directory preferences | ||
.directory | ||
|
||
# Linux trash folder which might appear on any partition or disk | ||
.Trash-* | ||
|
||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
|
||
### OSX ### | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
|
||
### Vim ### | ||
# swap | ||
[._]*.s[a-w][a-z] | ||
[._]s[a-w][a-z] | ||
# session | ||
Session.vim | ||
# temporary | ||
.netrwhist | ||
*~ | ||
# auto-generated tag files | ||
tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
'use strict'; | ||
|
||
const Node = require('./node'); | ||
|
||
const LinkedList = module.exports = function(array) { | ||
this.head = null; | ||
if(array) array.forEach(val => this.insert(val)); | ||
}; | ||
|
||
LinkedList.prototype.insert = function(val) { | ||
try { | ||
if (typeof val === 'undefined') { | ||
throw new ReferenceError('Please enter a value for the node.'); | ||
} else { | ||
this.head = new Node(val, this.head); | ||
return this; | ||
} | ||
} catch (err) { | ||
return err; | ||
} | ||
}; | ||
|
||
LinkedList.prototype.remove = function(val) { | ||
let current; | ||
try { | ||
if (typeof val === 'undefined') { | ||
throw new ReferenceError('Please enter a value for the node.'); | ||
} else if (this.search(val) === false){ | ||
throw new ReferenceError('That node does not exist in the list.'); | ||
} else { | ||
current = this.head; | ||
if (this.head.val === val) { | ||
this.head = current.next; | ||
current = null; | ||
return this; | ||
} else { | ||
while (current.next) { | ||
if (current.next.val === val) { | ||
current.next = current.next.next; | ||
return this; | ||
} else { | ||
current = current.next; | ||
} | ||
} | ||
} | ||
} | ||
} catch (err) { | ||
return err; | ||
} | ||
}; | ||
|
||
LinkedList.prototype.shift = function() { | ||
if(!this.head) throw new ReferenceError('The list is empty'); | ||
try { | ||
let current = this.head; | ||
this.head = this.head.next; | ||
current.next = null; | ||
return current.val; | ||
} catch (err) { | ||
return err; | ||
} | ||
}; | ||
|
||
LinkedList.prototype.search = function(val) { | ||
try { | ||
let current; | ||
if (typeof val === 'undefined') { | ||
throw new ReferenceError('Please enter a value for the node.'); | ||
} else { | ||
current = this.head; | ||
while (current.next) { | ||
if (current.val === val) { | ||
return current.val; | ||
} else { | ||
current = current.next; | ||
} | ||
} | ||
return current.val === val ? current.val : false; | ||
} | ||
} catch (err) { | ||
return err; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
function Node(val, next, prev) { | ||
this.val = val; | ||
this.next = next; | ||
this.prev = prev; | ||
} | ||
|
||
module.exports = Node; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const Queue = module.exports = require('./ll'); | ||
|
||
Queue.prototype.enqueue = function(val) { | ||
this.insert(val); | ||
return this; | ||
}; | ||
|
||
Queue.prototype.dequeue = function() { | ||
let current = null; | ||
|
||
_setCurrent(this.head); | ||
current.next = null; | ||
return this; | ||
|
||
function _setCurrent(node) { | ||
if(!node.next) return; | ||
current = node; | ||
_setCurrent(node.next); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
|
||
const Stack = module.exports = require('./ll'); | ||
|
||
Stack.prototype.push = function(val) { | ||
this.insert(val); | ||
return this; | ||
}; | ||
|
||
Stack.prototype.pop = function() { | ||
this.shift(); | ||
return this; | ||
}; | ||
|
||
Stack.prototype.peek = function() { | ||
return this.head.val; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
|
||
//O(n) notation | ||
|
||
const Stack = require('./lib/stack'); | ||
let openerStack = new Stack(); | ||
|
||
const Linter = module.exports = function(string) { | ||
|
||
for(let i = 0; i <string.length; i ++) { | ||
if(string.charAt(i) === '[' || string.charAt(i) === '{' || string.charAt(i) === '(') { | ||
openerStack.push(string[i]); | ||
} | ||
|
||
if(string.charAt(i) === ']' || string.charAt(i) === '}' || string.charAt(i) === ')') { | ||
if(openerStack.head === null) { | ||
return false; | ||
} | ||
|
||
let current = string.charAt(i); | ||
let top = openerStack.peek(); | ||
if(top === '[' && current === ']' || top === '{' && current === '}' || top === '(' && current === ')') { | ||
openerStack.pop(); | ||
} | ||
} | ||
} | ||
if(openerStack.head !== null) { | ||
return false; | ||
} | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "lab-shelly", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "balanced-bracket.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"author": "shelly", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"mocha": "^3.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
const expect = require('chai').expect; | ||
const Linter = require('../linter'); | ||
|
||
describe('Linter Module', function() { | ||
|
||
describe('a string with balanced openers and closers', function() { | ||
it('should return true', done => { | ||
let balancedTestStr = '[]{}()'; | ||
let testBalanced = Linter(balancedTestStr); | ||
expect(testBalanced).to.be.true; | ||
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 remember these tests... |
||
done(); | ||
}); | ||
}); | ||
|
||
describe('a string with an extra opening [ ( or { ', function() { | ||
it('should return false', done => { | ||
let openerTestString = '[]{'; | ||
let testOpener = Linter(openerTestString); | ||
expect(testOpener).to.be.false; | ||
done(); | ||
}); | ||
}); | ||
|
||
describe('a string with an extra closing ] ) or } ', function() { | ||
it('should return false', done => { | ||
let closerTestString = '[]{})'; | ||
let testCloser = Linter(closerTestString); | ||
expect(testCloser).to.be.false; | ||
done(); | ||
}); | ||
}); | ||
|
||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Great job with this linter function!