Skip to content

Instantly share code, notes, and snippets.

@LucasPadovan
Created September 5, 2018 15:51
Show Gist options
  • Save LucasPadovan/2e4d8a5b017c1e1b3cf9a83065ee543a to your computer and use it in GitHub Desktop.
Save LucasPadovan/2e4d8a5b017c1e1b3cf9a83065ee543a to your computer and use it in GitHub Desktop.
adjust array to center
console.clear();
const uno = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'];
let activeIndex = 1;
const visibleElements = 5;
const centerElement = parseInt(visibleElements / 2, 0);
const dos = uno.map((item, index) => {
let adjustedIndex = index + 2 + activeIndex;
let level = 3;
adjustedIndex = adjustedIndex % uno.length;
if (adjustedIndex < visibleElements) {
level = centerElement - adjustedIndex;
}
return {newIndex: adjustedIndex % uno.length, item, level};
})
console.log(dos);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment