Skip to content

Instantly share code, notes, and snippets.

@davidsharp
Created December 23, 2020 11:38
Show Gist options
  • Select an option

  • Save davidsharp/fe2fd4356e5e6c992e9f0eeddbdd5982 to your computer and use it in GitHub Desktop.

Select an option

Save davidsharp/fe2fd4356e5e6c992e9f0eeddbdd5982 to your computer and use it in GitHub Desktop.
Quick little function for getting indexes in arrays cyclically (-1 = last element, length+1 = first element)
const getIndex = (array,index) => array[(array.length+index)%array.length]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment