mirror of
https://github.com/10h30/odin-javascript-exercises.git
synced 2026-07-12 19:26:13 +09:00
Clean up the oopsie. Rebuild the blank exercises.
This commit is contained in:
+6
-5
@@ -1,7 +1,8 @@
|
||||
var Yallist = require('./yallist.js')
|
||||
|
||||
Yallist.prototype[Symbol.iterator] = function* () {
|
||||
for (let walker = this.head; walker; walker = walker.next) {
|
||||
yield walker.value
|
||||
'use strict'
|
||||
module.exports = function (Yallist) {
|
||||
Yallist.prototype[Symbol.iterator] = function* () {
|
||||
for (let walker = this.head; walker; walker = walker.next) {
|
||||
yield walker.value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
-12
@@ -1,27 +1,27 @@
|
||||
{
|
||||
"_from": "yallist@^2.1.2",
|
||||
"_id": "yallist@2.1.2",
|
||||
"_from": "yallist@^4.0.0",
|
||||
"_id": "yallist@4.0.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-HBH5IY8HYImkfdUS+TxmmaaoHVI=",
|
||||
"_integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==",
|
||||
"_location": "/yallist",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "yallist@^2.1.2",
|
||||
"raw": "yallist@^4.0.0",
|
||||
"name": "yallist",
|
||||
"escapedName": "yallist",
|
||||
"rawSpec": "^2.1.2",
|
||||
"rawSpec": "^4.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^2.1.2"
|
||||
"fetchSpec": "^4.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/lru-cache"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/yallist/-/yallist-2.1.2.tgz",
|
||||
"_shasum": "1c11f9218f076089a47dd512f93c6699a6a81d52",
|
||||
"_spec": "yallist@^2.1.2",
|
||||
"_where": "/Users/cloyd/coderrr/odin/javascript-exercises/node_modules/lru-cache",
|
||||
"_resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
|
||||
"_shasum": "9bb92790d9c0effec63be73519e11a35019a3a72",
|
||||
"_spec": "yallist@^4.0.0",
|
||||
"_where": "/home/michael/projects/javascript-exercises/node_modules/lru-cache",
|
||||
"author": {
|
||||
"name": "Isaac Z. Schlueter",
|
||||
"email": "i@izs.me",
|
||||
@@ -35,7 +35,7 @@
|
||||
"deprecated": false,
|
||||
"description": "Yet Another Linked List",
|
||||
"devDependencies": {
|
||||
"tap": "^10.3.0"
|
||||
"tap": "^12.1.0"
|
||||
},
|
||||
"directories": {
|
||||
"test": "test"
|
||||
@@ -58,5 +58,5 @@
|
||||
"preversion": "npm test",
|
||||
"test": "tap test/*.js --100"
|
||||
},
|
||||
"version": "2.1.2"
|
||||
"version": "4.0.0"
|
||||
}
|
||||
|
||||
+56
@@ -1,3 +1,4 @@
|
||||
'use strict'
|
||||
module.exports = Yallist
|
||||
|
||||
Yallist.Node = Node
|
||||
@@ -53,6 +54,8 @@ Yallist.prototype.removeNode = function (node) {
|
||||
node.next = null
|
||||
node.prev = null
|
||||
node.list = null
|
||||
|
||||
return next
|
||||
}
|
||||
|
||||
Yallist.prototype.unshiftNode = function (node) {
|
||||
@@ -317,6 +320,37 @@ Yallist.prototype.sliceReverse = function (from, to) {
|
||||
return ret
|
||||
}
|
||||
|
||||
Yallist.prototype.splice = function (start, deleteCount, ...nodes) {
|
||||
if (start > this.length) {
|
||||
start = this.length - 1
|
||||
}
|
||||
if (start < 0) {
|
||||
start = this.length + start;
|
||||
}
|
||||
|
||||
for (var i = 0, walker = this.head; walker !== null && i < start; i++) {
|
||||
walker = walker.next
|
||||
}
|
||||
|
||||
var ret = []
|
||||
for (var i = 0; walker && i < deleteCount; i++) {
|
||||
ret.push(walker.value)
|
||||
walker = this.removeNode(walker)
|
||||
}
|
||||
if (walker === null) {
|
||||
walker = this.tail
|
||||
}
|
||||
|
||||
if (walker !== this.head && walker !== this.tail) {
|
||||
walker = walker.prev
|
||||
}
|
||||
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
walker = insert(this, walker, nodes[i])
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Yallist.prototype.reverse = function () {
|
||||
var head = this.head
|
||||
var tail = this.tail
|
||||
@@ -330,6 +364,23 @@ Yallist.prototype.reverse = function () {
|
||||
return this
|
||||
}
|
||||
|
||||
function insert (self, node, value) {
|
||||
var inserted = node === self.head ?
|
||||
new Node(value, null, node, self) :
|
||||
new Node(value, node, node.next, self)
|
||||
|
||||
if (inserted.next === null) {
|
||||
self.tail = inserted
|
||||
}
|
||||
if (inserted.prev === null) {
|
||||
self.head = inserted
|
||||
}
|
||||
|
||||
self.length++
|
||||
|
||||
return inserted
|
||||
}
|
||||
|
||||
function push (self, item) {
|
||||
self.tail = new Node(item, self.tail, null, self)
|
||||
if (!self.head) {
|
||||
@@ -368,3 +419,8 @@ function Node (value, prev, next, list) {
|
||||
this.next = null
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
// add if support for Symbol.iterator is present
|
||||
require('./iterator.js')(Yallist)
|
||||
} catch (er) {}
|
||||
|
||||
Reference in New Issue
Block a user