Skip to content

Instantly share code, notes, and snippets.

@lotusirous
Last active May 2, 2017 01:15
Show Gist options
  • Save lotusirous/aaf906fdf63f3972c6e3d213a2449126 to your computer and use it in GitHub Desktop.
Save lotusirous/aaf906fdf63f3972c6e3d213a2449126 to your computer and use it in GitHub Desktop.
var tvshows = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
var show_range = 5;
var focus_pos = 0;
var ArrayLookup = function (pos) {
// pos is beginning of Lookup Array
var ret = [];
// tvshows => [0, 1, 2, 3, 4]
//
if ((pos + show_range) > tvshows.length) {
for (var i = pos; i < tvshows.length; i++) {
ret.push(tvshows[i]);
}
for (var i = 0; i < (pos + show_range - tvshows.length); i++) {
ret.push(tvshows[i]);
}
} else {
for (var i = pos; i < (pos + show_range); i++) {
ret.push(tvshows[i]);
}
}
return ret;
}
function next() {
focus_pos++;
if (focus_pos > 4) {
array_pos = array_pos + 5;
// refresh display
// check array_pos
if (array_pos > tvshows.length) {
array_pos = array_pos - tvshows.length;
}
display_array = ArrayLookup(array_pos);
focus_pos = 0;
}
}
function previous() {
focus_pos--;
if (focus_pos < 0) {
array_pos = array_pos - 5;
// refresh display
// check array_pos
if (array_pos < 0) {
array_pos = tvshows.length + array_pos;
}
display_array = ArrayLookup(array_pos);
focus_pos = 4;
}
}
function init() {
array_pos = 0;
display_array = ArrayLookup(array_pos);
focus_pos = 2;
}
init();
function printdata() {
console.log(array_pos + ":" + display_array[focus_pos]);
console.log(display_array);
}
for (var i = 0; i < 40; i++) {
printdata();
// previous();
next();
console.log("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment