A LinkedList in JavaScript
JavaScript
Switch branches/tags
Nothing to show
Latest commit f960eaf Dec 2, 2010 @kirbysayshi readme update
Permalink
Failed to load latest commit information.
HookShot.js
README.md
tests.html

README.md

HookShot

This is a simple linked list, implemented in JS. At its core is an object called a Link, which is simply the wrapper for the actual data. The HookShot has an internal pointer that can be reset().

The code is documented well enough... but here's what you can do to a HookShot:

  • iteration: next(), reset(), forEach(), where()
  • mutation: push(), pop(), detachCurrent(), join(), select()
  • transformation: flatten(), clone()
  • query: select(), where()

Usage:

var l = new HookShot('a')
	.push('b')
	.push('c')
	.push('d')
	.push('e');
	
var w = l.where(function(value, idx){
	if(value == 'c' || value == 'e') return true;
});

// w contains two links, with values of 'c' and 'e'
// l remains unchanged
	
var s = l.select(function(value, idx){
	if(value == 'c') return true;
});

// s contains 1 link, with value of 'c'
// l now contains only 4 links

var a = l.flatten();
// a is now a simple array of the ordered values from s
// ['a', 'b', 'd', 'e']
// l is unchanged

l.forEach(function(val, idx){
	console.log(val);
});
// logs: 'a', 'b', 'd', 'e'