basant307/AI_Governance_Project
048
1# yallist2 3Yet Another Linked List4 5There are many doubly-linked list implementations like it, but this6one is mine.7 8For when an array would be too big, and a Map can't be iterated in9reverse order.10 11 12[](https://travis-ci.org/isaacs/yallist) [](https://coveralls.io/github/isaacs/yallist)13 14## basic usage15 16```javascript17var yallist = require('yallist')18var myList = yallist.create([1, 2, 3])19myList.push('foo')20myList.unshift('bar')21// of course pop() and shift() are there, too22console.log(myList.toArray()) // ['bar', 1, 2, 3, 'foo']23myList.forEach(function (k) {24 // walk the list head to tail25})26myList.forEachReverse(function (k, index, list) {27 // walk the list tail to head28})29var myDoubledList = myList.map(function (k) {30 return k + k31})32// now myDoubledList contains ['barbar', 2, 4, 6, 'foofoo']33// mapReverse is also a thing34var myDoubledListReverse = myList.mapReverse(function (k) {35 return k + k36}) // ['foofoo', 6, 4, 2, 'barbar']37 38var reduced = myList.reduce(function (set, entry) {39 set += entry40 return set41}, 'start')42console.log(reduced) // 'startfoo123bar'43```44 45## api46 47The whole API is considered "public".48 49Functions with the same name as an Array method work more or less the50same way.51 52There's reverse versions of most things because that's the point.53 54### Yallist55 56Default export, the class that holds and manages a list.57 58Call it with either a forEach-able (like an array) or a set of59arguments, to initialize the list.60 61The Array-ish methods all act like you'd expect. No magic length,62though, so if you change that it won't automatically prune or add63empty spots.64 65### Yallist.create(..)66 67Alias for Yallist function. Some people like factories.68 69#### yallist.head70 71The first node in the list72 73#### yallist.tail74 75The last node in the list76 77#### yallist.length78 79The number of nodes in the list. (Change this at your peril. It is80not magic like Array length.)81 82#### yallist.toArray()83 84Convert the list to an array.85 86#### yallist.forEach(fn, [thisp])87 88Call a function on each item in the list.89 90#### yallist.forEachReverse(fn, [thisp])91 92Call a function on each item in the list, in reverse order.93 94#### yallist.get(n)95 96Get the data at position `n` in the list. If you use this a lot,97probably better off just using an Array.98 99#### yallist.getReverse(n)100 101Get the data at position `n`, counting from the tail.102 103#### yallist.map(fn, thisp)104 105Create a new Yallist with the result of calling the function on each106item.107 108#### yallist.mapReverse(fn, thisp)109 110Same as `map`, but in reverse.111 112#### yallist.pop()113 114Get the data from the list tail, and remove the tail from the list.115 116#### yallist.push(item, ...)117 118Insert one or more items to the tail of the list.119 120#### yallist.reduce(fn, initialValue)121 122Like Array.reduce.123 124#### yallist.reduceReverse125 126Like Array.reduce, but in reverse.127 128#### yallist.reverse129 130Reverse the list in place.131 132#### yallist.shift()133 134Get the data from the list head, and remove the head from the list.135 136#### yallist.slice([from], [to])137 138Just like Array.slice, but returns a new Yallist.139 140#### yallist.sliceReverse([from], [to])141 142Just like yallist.slice, but the result is returned in reverse.143 144#### yallist.toArray()145 146Create an array representation of the list.147 148#### yallist.toArrayReverse()149 150Create a reversed array representation of the list.151 152#### yallist.unshift(item, ...)153 154Insert one or more items to the head of the list.155 156#### yallist.unshiftNode(node)157 158Move a Node object to the front of the list. (That is, pull it out of159wherever it lives, and make it the new head.)160 161If the node belongs to a different list, then that list will remove it162first.163 164#### yallist.pushNode(node)165 166Move a Node object to the end of the list. (That is, pull it out of167wherever it lives, and make it the new tail.)168 169If the node belongs to a list already, then that list will remove it170first.171 172#### yallist.removeNode(node)173 174Remove a node from the list, preserving referential integrity of head175and tail and other nodes.176 177Will throw an error if you try to have a list remove a node that178doesn't belong to it.179 180### Yallist.Node181 182The class that holds the data and is actually the list.183 184Call with `var n = new Node(value, previousNode, nextNode)`185 186Note that if you do direct operations on Nodes themselves, it's very187easy to get into weird states where the list is broken. Be careful :)188 189#### node.next190 191The next node in the list.192 193#### node.prev194 195The previous node in the list.196 197#### node.value198 199The data the node contains.200 201#### node.list202 203The list to which this node belongs. (Null if it does not belong to204any list.)205 