Skip to content

lab-kayla--resubmit #11

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 6 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-kayla/.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-kayla/.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
Empty file added lab-kayla/README.md
Empty file.
74 changes: 74 additions & 0 deletions lab-kayla/lib/linked-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

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

const SLL = module.exports = function() {
this.head = null;
};

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;
};

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.remove = function(val){
let current = this.head;
if(current.val === val){
this.head = current.next;
}
else {
let last = current;
while(current.next){
if(current.val === val){
last.next = current.next;
return;
}
last = current;
current = current.next;
}
if(current.val === val){
last.next === null;
}
}
};

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

while(current) {
next = current.next;
current.next = previousNode;
previousNode = current;
current = next;
}
this.head = previousNode;
};
6 changes: 6 additions & 0 deletions lab-kayla/lib/sll-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;
};
16 changes: 16 additions & 0 deletions lab-kayla/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "lab-kayla",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "mocha"
},
"author": "",
"license": "MIT",
"devDependencies": {
"chai": "^3.5.0",
"chai-http": "^3.0.0",
"mocha": "^3.3.0"
}
}
1 change: 1 addition & 0 deletions lab-kayla/test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'use strict';