https://github.com/valueof/peakle
A tiny abstraction around lists that makes them more walkable.
https://github.com/valueof/peakle
Last synced: 9 months ago
JSON representation
A tiny abstraction around lists that makes them more walkable.
- Host: GitHub
- URL: https://github.com/valueof/peakle
- Owner: valueof
- License: mit
- Created: 2012-08-10T05:57:29.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2021-08-30T18:13:57.000Z (almost 5 years ago)
- Last Synced: 2024-11-13T01:06:36.002Z (over 1 year ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: LICENSE
Awesome Lists containing this project
README
Peakle is a tiny abstraction around lists that makes them more walkable.
Peakle's constructor takes only one parameter, a list of values.
var peakled = new Peakle([ 1, 2, 3 ]);
By default, the current position is always at the first element. If the
initial list is empty, then the current position is 'null'.
Properties:
* length: returns a number of elements in the underlying list.
* current: returns a value of the current element.
Methods:
* next(): Moves to the next element and returns its value.
* prev(): Moves to the previous element and returns its value.
* peak(adv): Returns next element's value without moving its pointer.
This method accepts an optional numeric parameter. Use it if you
want to peak further.
* move(index): Moves to the specified element.
All methods return 'null' if they can't return a value.
Example:
var peakled = new Peakle([ 1, 2, 3 ]);
peakled.current; // 1
peakled.peak(); // 2
peakled.peak(2); // 3
peakled.next(); // 2
peakled.peak(); // 3
peakled.peak(2); // null
peakled.peak(-1); // 1
peakled.prev(); // 1
peakled.move(2); // 3