Conversation
added several stack functions with tests
renamed test files and added in Queue function
…data-structures into day2DataStructures
…data-structures into day2DataStructures
* WIP for PQueue * WIP for PQueue * set WIP * WIP for Set * Linked List
Day2 data structures
added work for several structures
finished linkedList
finished double linked list
mantinone
left a comment
There was a problem hiding this comment.
Sorry I ran out of time! I can review your tests later if you like.
| insertAfter(item, data) { | ||
| const newNode = new Node(data) | ||
|
|
||
| if (this.find(item) === this.tail { |
There was a problem hiding this comment.
There was a syntax error here that had to be fixed before tests could be run. (the if statement is not enclosed)
There was a problem hiding this comment.
Also, you left a couple console logs in here.
| return count | ||
| } | ||
|
|
||
| } |
There was a problem hiding this comment.
Looks good! I would try using your own length function instead of the built in length property, just for the heck of it.
| forEach(func) { | ||
| this.elements = this.elements.map(func) | ||
| return this.elements | ||
| } |
There was a problem hiding this comment.
I feel like this should be implemented differently for learning purposes. You have essentially used Map to implement Map.
| return count | ||
| } | ||
|
|
||
| } |
| return index == self.indexOf(element); | ||
| }) | ||
| return unique | ||
| } |
There was a problem hiding this comment.
This is a pretty clever way of doing it.
| } | ||
| return null | ||
| } | ||
|
|
There was a problem hiding this comment.
You're repeating this "Find the max" "Find the min" code a few times here. It would be a good idea to break these out into helper functions so they don't have to be repeated, and it helps make the code more easily readable, too.
| return this.find(item) !== -1 | ||
| } | ||
|
|
||
| } |
| contains(item) { | ||
| return this.find(item) !== -1 | ||
| } | ||
| } |
| @@ -1 +1,3 @@ | |||
| node_modules/ | |||
| lib/ | |||
| .gitignore | |||
There was a problem hiding this comment.
I'm not even sure you can ignore the .gitignore from within the .gitignore itself. That seems paradoxical :p
| _Provide a brief, high-level overview of what the final product (artifact) of this goal is. Include any relevant resources or dependencies here._ | ||
|
|
||
| Base repository for the [Core Data Structures](https://github.com/GuildCrafts/web-development-js/issues/127) goal. | ||
| Write tests and implementations for common data structures. |
| @@ -0,0 +1,156 @@ | |||
| 'use strict'; | |||
There was a problem hiding this comment.
it looks like you've checked in a transpiled version of one of your source files. These generally are not committed.
| @@ -1 +1,3 @@ | |||
| node_modules/ | |||
| lib/ | |||
There was a problem hiding this comment.
lib is in your git ignore but you are still tracking files within lib. git rm -df lib/* and then commit the removal of these files from tracking
| expect(doubleLinkedList.contains('foo')) | ||
| .to.be.true | ||
| expect(doubleLinkedList.contains('tap')) | ||
| .to.equal(false) |
| return true | ||
| } | ||
| return false | ||
|
|
|
|
||
| } | ||
|
|
||
| contains(value) { |
There was a problem hiding this comment.
contains(value) {
return this.elements.indexOf(value) !== -1
}|
|
||
| remove(value) { | ||
| if (this.elements.indexOf(value) > 0) { | ||
| return this.elements.splice(this.elements.indexOf(value),1) |
There was a problem hiding this comment.
remove(value) {
if (this.contains(value)) return false
this.elements = this.elements.filter(member => member !== value)
return true
}| } | ||
|
|
||
| forEach(func) { | ||
| this.elements = this.elements.map(func) |
There was a problem hiding this comment.
this would be better
forEach(iterator) {
this.elements.forEach(iterator)
return this
}This would be better for your learning
forEach(iterator) {
for (let i = this.length - 1; i >= 0; i--) {
iterator(this.elements[i], i)
}
return this
}| } | ||
|
|
||
| size() { | ||
| let count = 0 |
There was a problem hiding this comment.
for this exercise you should be tracking size so you don't have to rely on the elements array to calculate it
check out this data