Created
September 5, 2018 15:51
-
-
Save LucasPadovan/2e4d8a5b017c1e1b3cf9a83065ee543a to your computer and use it in GitHub Desktop.
adjust array to center
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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