Skip to content

Lab-teddy #6

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
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions lab-teddy/.eslintrc
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"
}
65 changes: 65 additions & 0 deletions lab-teddy/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Created by https://www.gitignore.io/api/osx,linux,node,vim

### OSX ###
.DS_Store
.AppleDouble
.LSOverride

### 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

# 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

### Vim ###
# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~

# auto-generated tag files
tags
8 changes: 8 additions & 0 deletions lab-teddy/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: node_js
node_js:
- "4"
sudo: required
before_script:
- npm install -g eslint mocha chai gulp
script:
- ./script/test-submissions.sh
14 changes: 14 additions & 0 deletions lab-teddy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Description:

### For this lab we were seeing how the methods for removing, appending, reverse and remove work with. We created the functions to help better understand at a lower level what exatly will need to be placed into the function to make the Nodes do what they are supposed to.

# Install Mocha and Chai steps:

### First you need to get the package.json file written and the way that you do this is:

`npm init` in your terminal and fill out all the information that is needed.

### Next you need to install Mocha and Chai and this is how:

`npm i -D mocha`
`npm i -D chai` This will install the test procedures that are needed to get them to run.
6 changes: 6 additions & 0 deletions lab-teddy/lib/list-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'use strict';

module.exports = function(value){
this.val = value;
this.next = null;
};
70 changes: 70 additions & 0 deletions lab-teddy/lib/sll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'use strict';

const Node = require('./list-node.js');

const SLL = module.exports = function(){
this.head = null;
};
//O(n)
SLL.prototype.prepend = function(value){
let node = new Node(value);
if(!this.head){
this.head = node;
return this;
}
node.next = this.head;
this.head = node;
return this;
};

//O(n)
SLL.prototype.append = function(value){
let node = new Node(value);
let lastNode = null;

if(!this.head){
this.head = node;
return this;
}
_setLastNode(this.head);
lastNode.next = node;
return this;

function _setLastNode(node){
if(!node)return;
lastNode = node;
_setLastNode(node.next);
}
};

SLL.prototype.reverse = function(){
let current = this.head;
let previous = null;
let next;

while(current){
next = current.next;
current.next = previous;
previous = current;
current = next;
}
this.head = previous;
};

//O(n)
SLL.prototype.remove = function(value){
if(this.head.val === value){
this.head = this.head.next;
} else {
let previousNode = this.head;
let currentNode = previousNode.next;
while(currentNode){
if(currentNode === value){
previousNode.next = currentNode.next;
} else {
previousNode = currentNode;
currentNode = currentNode.next;
}
}
}
};
31 changes: 31 additions & 0 deletions lab-teddy/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "lab-teddy",
"version": "1.0.0",
"description": "node functions",
"main": "sll.js",
"directories": {
"test": "tests"
},
"scripts": {
"test": "mocha"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tedsters/lab-10-career-development.git"
},
"keywords": [
"node",
"algorithums",
"tests"
],
"author": "David Teddy",
"license": "MIT",
"bugs": {
"url": "https://github.com/tedsters/lab-10-career-development/issues"
},
"homepage": "https://github.com/tedsters/lab-10-career-development#readme",
"devDependencies": {
"chai": "^3.5.0",
"mocha": "^3.3.0"
}
}
1 change: 1 addition & 0 deletions lab-teddy/tests/sll-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';