Last change
on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
485 bytes
|
Line | |
---|
1 | function incrementListIndex(current, dir, opt) {
|
---|
2 | const len = opt.choices.realLength;
|
---|
3 | const shouldLoop = 'loop' in opt ? Boolean(opt.loop) : true;
|
---|
4 | if (dir === 'up') {
|
---|
5 | if (current > 0) {
|
---|
6 | return current - 1;
|
---|
7 | }
|
---|
8 | return shouldLoop ? len - 1 : current;
|
---|
9 | }
|
---|
10 | if (dir === 'down') {
|
---|
11 | if (current < len - 1) {
|
---|
12 | return current + 1;
|
---|
13 | }
|
---|
14 | return shouldLoop ? 0 : current;
|
---|
15 | }
|
---|
16 | throw new Error('dir must be up or down');
|
---|
17 | }
|
---|
18 |
|
---|
19 | module.exports = incrementListIndex;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.