Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
siawyoung committed Mar 28, 2016
1 parent 19c21c6 commit cb28dcf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -2,4 +2,14 @@

This collection is a side effect of my picking up some TypeScript over the weekend.

Tests are also included - simply `git clone` and run `npm test`.
- [x] Array
- [x] Stack
- [x] Queue
- [x] Binary Search Tree
- [x] Graph

I'm still wary of using JavaScript classes, and my intuition tells me that using TypeScript reinforces that style of thinking in classical inheritance. So I opted instead to write the structures in the classical JavaScript prototypical style.

I also included Lodash in the project just to learn how to import external libraries for use in TypeScript environments.

Tests are also included (except for graphs, because the weekend is over). Not all batteries are included though - you have to have TypeScript installed globally: `npm install typescript -g`. Then `npm install` and run `npm test`.
10 changes: 8 additions & 2 deletions bst.ts
@@ -1,18 +1,24 @@

/*
Binary search tree
*/

interface binaryTreeNode {
minValue(): any,
}

interface binarySearchTree {
root() : binaryTreeNode,
size() : number,
add(item: any) : binarySearchTree,
search(item: any) : boolean,
remove(item: any) : binarySearchTree,
isEqual(node: binarySearchTree): boolean
preOrderTraversal(fn: (item: binaryTreeNode) => void) : void,
inOrderTraversal(fn: (item: binaryTreeNode) => void) : void,
postOrderTraversal(fn: (item: binaryTreeNode) => void) : void,
size() : number,
isEqual(node: binarySearchTree): boolean
}

const binaryTreeNode = (item, leftItem?, rightItem?) => {
Expand Down
2 changes: 0 additions & 2 deletions graph.ts
@@ -1,6 +1,4 @@

import * as _ from 'lodash'

interface graphType {
addNode(item: any): void
removeNode(item: any): void
Expand Down
4 changes: 1 addition & 3 deletions package.json
Expand Up @@ -13,8 +13,6 @@
"ava": "^0.13.0"
},
"dependencies": {
"lodash": "^4.6.1",
"lodash.isequal": "^4.1.1",
"tape": "^4.5.1"
"lodash": "^4.6.1"
}
}
8 changes: 4 additions & 4 deletions queue.ts
@@ -1,9 +1,9 @@

interface queueType {
length(): number
enqueue(item: any): queueType
dequeue(item: any): any
peek(): any
length() : number
enqueue(item: any) : queueType
dequeue(item: any) : any
peek() : any
}

const queue = () => {
Expand Down

0 comments on commit cb28dcf

Please sign in to comment.