-
Notifications
You must be signed in to change notification settings - Fork 0
Js stack #10
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
Open
chelseadole
wants to merge
44
commits into
master
Choose a base branch
from
js-stack
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
Js stack #10
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
e755882
finished adding autocmplete, left over from last week
chelseadole c1a9d65
adding two new tests to autocmplete in trie.
chelseadole ceba63c
one more test
chelseadole 6ebce10
assert StopIteration when done.
chelseadole 9cae6ed
adding error handling for non string input.
chelseadole 27d365c
last insertion sort stuff.
chelseadole 7658d49
finished insertion sort.
chelseadole 917a87a
renaming insertion sort files to use underscore.
chelseadole aa86758
adding first tests for insertion sort.
chelseadole 3ff4b28
changing test paramerization.
chelseadole 5364b43
adding last test for randomized long lsts.
chelseadole 40f09c3
adding test to check for negative numbers.
chelseadole 1f40505
adding to README.
chelseadole 591ff2e
adding timeit and if name is main to insertion sort.
chelseadole 63d10db
creating files for LL and DLL in js-src file
chelseadole f406f80
adding constructor to LL.
chelseadole 7145bdc
added semi colon bois
chelseadole 94ac35e
adding more curlybois and adding push and pop fns.
chelseadole 842cc34
added pop function completed.
chelseadole 826cd56
added size() on LL and DLL
chelseadole 43bdd12
adding remove and serach to DLL and LL.
chelseadole 9505bd5
more remove method work.
chelseadole 1c63770
adding more methods to DLL, fixing tail method of LL.
chelseadole e51d0d5
adding first two sketchy af chai tests.
chelseadole 300e9d4
adding more tests to js-linked-list.
chelseadole fd73506
adding more to linked-list test.
chelseadole 29004cf
adding node_modules to gitignore and also more test bois
chelseadole 27073c0
fixing tests for linked-list in JS.
chelseadole b4503b2
fixing syntax of JS errors.
chelseadole 8948b6f
broke some shit
chelseadole 28037ac
all tests passing :squidab: :ho-ho-ho:
chelseadole bd158a0
adding changes to README.
chelseadole 95993a7
changing throws to returns.
chelseadole 33c5861
return not throw shit
chelseadole 567ba98
changing dll tests
chelseadole 759b2d9
adding module.exports, extra tests.
chelseadole 4704bd6
trouble shooting remove() method to work with a one-node list.
chelseadole 2818165
deleting semicolon bois
chelseadole f59a17a
fixing tests and throwing errors.
chelseadole 0790f12
two extra empty files
chelseadole a98ced0
adding js-stack contents. Copying linked-list tests to edit.
chelseadole c07cfe9
fixing js-stack tests.
chelseadole b4fb3c2
adding last stack stuff.
chelseadole a70da4d
adding to README.
chelseadole 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 hidden or 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 |
|---|---|---|
|
|
@@ -99,3 +99,4 @@ ENV/ | |
|
|
||
| # mypy | ||
| .mypy_cache/ | ||
| node_modules/ | ||
This file contains hidden or 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
This file contains hidden or 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,138 @@ | ||
| "use strict"; | ||
|
|
||
| class Node { | ||
| constructor(data, nextNode=null, prevNode=null) { | ||
| this.data = data | ||
| this.nextNode = nextNode | ||
| this.prevNode = prevNode | ||
| } | ||
| } | ||
|
|
||
| class DLL { | ||
| constructor(iter=null) { | ||
| this.head = null | ||
| this.tail = null | ||
| this.counter = 0 | ||
| if (Array.isArray(iter)) { | ||
| iter.forEach(item => this.push(item)) | ||
| } | ||
| else if (iter !== null) { | ||
| throw 'LinkedList only takes arrays as inputs.' | ||
| } | ||
| } | ||
|
|
||
| push(val) { | ||
| this.head = new Node(val, this.head) | ||
| this.counter ++ | ||
| if (this.size() === 1) { | ||
| this.tail = this.head | ||
| } else { | ||
| this.head.nextNode.prevNode = this.head | ||
| } | ||
| } | ||
|
|
||
| pop() { | ||
| if (this.size() === 0) { | ||
| throw 'Cannot pop() from empty DoublyLinkedList.' | ||
| } | ||
| this.counter -- | ||
| var output = this.head.data | ||
| this.head = this.head.nextNode | ||
| if (this.head) { | ||
| this.head.prevNode = null | ||
| } | ||
| return output | ||
| } | ||
|
|
||
| size() { | ||
| return this.counter | ||
| } | ||
|
|
||
| search(val) { | ||
| var curr = this.head | ||
| while (curr.data !== val) { | ||
| if (curr.nextNode === null) { | ||
| throw 'This value is not in the LinkedList.' | ||
| } | ||
| curr = curr.nextNode | ||
| } | ||
| return curr | ||
| } | ||
|
|
||
| remove(val) { | ||
| var curr = this.head | ||
| var prev = null | ||
| while (curr) { | ||
| if (curr.data == val) { | ||
| this.counter -- | ||
| if (curr == this.head) { | ||
| if (this.head == this.tail) { | ||
| this.head = null | ||
| this.tail = null | ||
| return curr.data | ||
| } | ||
| this.head = curr.nextNode | ||
| this.head.prevNode = null | ||
| return curr.data | ||
| } | ||
| prev.nextNode = curr.nextNode | ||
| curr.nextNode.prevNode = prev | ||
| return curr.data | ||
| } | ||
| if (curr.nextNode == null) { | ||
| throw 'Values not in the DoublyLinkedList cannot be removed.' | ||
| } | ||
| prev = curr | ||
| curr = curr.nextNode | ||
| } | ||
| return curr | ||
| } | ||
|
|
||
| append(val){ | ||
| var firstTail = this.tail | ||
| this.tail = new Node(val, this.prevNode=this.tail) | ||
| this.counter ++ | ||
| if(firstTail){ | ||
| firstTail.nextNode = this.tail | ||
| } else { | ||
| this.head = this.tail | ||
| } | ||
| this.tail.nextNode = null | ||
| } | ||
|
|
||
| shift(){ | ||
| if (!this.tail){ | ||
| throw "Cannot shift() from empty DLL." | ||
| } | ||
| var output = this.tail.data | ||
| this.tail = this.tail.prevNode | ||
| if(this.tail) { | ||
| this.tail.nextNode = null | ||
| } else { | ||
| this.head = null | ||
| } | ||
| this.counter -- | ||
| return output | ||
| } | ||
|
|
||
|
|
||
| display() { | ||
| var start_paren = "(" | ||
| if (this.head === null) { | ||
| return '()' | ||
| } | ||
| var curr = this.head | ||
| while (curr) { | ||
| if (curr.nextNode === null) { | ||
| start_paren += curr.data + ')' | ||
| return start_paren | ||
| } | ||
| else { | ||
| start_paren += curr.data + ', ' | ||
| curr = curr.nextNode | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = DLL |
This file contains hidden or 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,95 @@ | ||
| 'use strict'; | ||
|
|
||
| class Node { | ||
| constructor(data, nextNode=null) { | ||
| this.data = data; | ||
| this.nextNode = nextNode; | ||
| } | ||
| } | ||
|
|
||
| class LL { | ||
| constructor(iter=null) { | ||
| this.head = null; | ||
| this.counter = 0; | ||
| if (Array.isArray(iter)) { | ||
| iter.forEach(item => this.push(item)); | ||
| } | ||
| else if (iter !== null) { | ||
| return 'LinkedList only takes arrays as inputs.'; | ||
| } | ||
| } | ||
|
|
||
| push(val) { | ||
| this.head = new Node(val, this.head); | ||
| this.counter ++; | ||
| } | ||
|
|
||
| pop() { | ||
| if (this.counter === 0) { | ||
| return 'Cannot pop() from empty LinkedList.'; | ||
| } | ||
| var output = this.head.data; | ||
| this.head = this.head.nextNode; | ||
| this.counter --; | ||
| return output; | ||
| } | ||
|
|
||
| size() { | ||
| return this.counter; | ||
| } | ||
|
|
||
| search(val) { | ||
| var curr = this.head; | ||
| while (curr.data !== val) { | ||
| if (curr.nextNode === null) { | ||
| return 'This value is not in the LinkedList.'; | ||
| } | ||
| curr = curr.nextNode; | ||
| } | ||
| return curr; | ||
| } | ||
|
|
||
| remove(val) { | ||
| var curr = this.head; | ||
| if (this.head.data === val) { | ||
| this.head = this.head.nextNode; | ||
| this.counter --; | ||
| return val; | ||
| } | ||
| if (this.head === null) { | ||
| return 'Cannot remove vals from empty LinkedList.'; | ||
| } | ||
| while (curr) { | ||
| if (curr.nextNode === null) { | ||
| return 'Values not in the LinkedList cannot be removed.'; | ||
| } | ||
| else if (curr.nextNode.data === val) { | ||
| curr.nextNode = curr.nextNode.nextNode; | ||
| this.counter --; | ||
| return val; | ||
| } | ||
| curr = curr.nextNode; | ||
| } | ||
| } | ||
|
|
||
| display() { | ||
| var start_paren = '('; | ||
| if (this.head === null) { | ||
| return '()'; | ||
| } | ||
| var curr = this.head; | ||
| while (curr) { | ||
| if (curr.nextNode === null) { | ||
| start_paren += curr.data + ')'; | ||
| return start_paren; | ||
| } | ||
| else { | ||
| start_paren += curr.data + ', '; | ||
| curr = curr.nextNode; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = LL; | ||
|
|
Empty file.
This file contains hidden or 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,28 @@ | ||
| "use strict"; | ||
|
|
||
| const LL = require("./js-linked-list") | ||
| // import {LL} from "js-linked-list.js" | ||
|
|
||
| class Stack { | ||
| constructor(iter=null){ | ||
| this.linked = new LL() | ||
| if(Array.isArray(iter)){ | ||
| iter.forEach(item => this.push(item)) | ||
| } | ||
| } | ||
|
|
||
| size(){ | ||
| return this.linked.size() | ||
| } | ||
|
|
||
| push(val){ | ||
| this.linked.push(val) | ||
| } | ||
|
|
||
| pop(){ | ||
| return this.linked.pop() | ||
| } | ||
|
|
||
| } | ||
|
|
||
| module.exports = Stack | ||
This file contains hidden or 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 @@ | ||
| { | ||
| "name": "js-data-structures", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "main": "js-linked-list.js", | ||
| "dependencies": { | ||
| "chai": "^4.1.2" | ||
| }, | ||
| "devDependencies": { | ||
| "mocha": "^4.0.1" | ||
| }, | ||
| "scripts": { | ||
| "test": "mocha" | ||
| }, | ||
| "author": "Ya bish", | ||
| "license": "ISC" | ||
| } |
Oops, something went wrong.
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.
If you don't need this line get rid of it