1 | ;
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.lrange = lrange;
|
7 | /**
|
8 | * Returns the specified elements of the list stored at key. The offsets start and stop are zero-based indexes, with 0 being the first element of the list (the head of the list), 1 being the next element and so on.
|
9 | * These offsets can also be negative numbers indicating offsets starting at the end of the list. For example, -1 is the last element of the list, -2 the penultimate, and so on.
|
10 | *
|
11 | * @param {string} key
|
12 | * @param {string} start Start index
|
13 | * @param {string} end End index (included in returned range)
|
14 | * @return {Array} An array in the defined range
|
15 | */
|
16 | function lrange(key, s, e) {
|
17 | if (this.data.has(key) && !(this.data.get(key) instanceof Array)) {
|
18 | throw new Error("Key " + key + " does not contain a list");
|
19 | }
|
20 | var start = parseInt(s, 10);
|
21 | var end = parseInt(e, 10);
|
22 |
|
23 | var list = this.data.get(key) || [];
|
24 |
|
25 | if (start < 0) {
|
26 | start = list.length + start;
|
27 | }
|
28 | if (end < 0) {
|
29 | end = list.length + end;
|
30 | }
|
31 |
|
32 | return list.slice(start, end + 1);
|
33 | } |
\ | No newline at end of file |