Skip to content

Instantly share code, notes, and snippets.

@atomita
Last active February 6, 2019 02:56
Show Gist options
  • Save atomita/cbc978b353a6c1da4623453654f5b838 to your computer and use it in GitHub Desktop.
Save atomita/cbc978b353a6c1da4623453654f5b838 to your computer and use it in GitHub Desktop.
function pages(current, max, length) {
return new Array(length * 2 - 1).fill(0) // 0埋めの配列(empty埋めの配列だとmapが実行されない)
.map((_, n)=> current + (Math.cos(Math.PI * n) * (n + 0.5) - 0.5) / -2) // current+0,current+1,current+-1,current+2...な配列にする
.filter((n)=> 0 < n && n <= max )
.slice(0, length)
.sort((a, b)=> a < b ? -1 : 1 );
}
// `Array.prototype.fill`が利用できない場合は
// `new Array(length * 2 - 1).fill(0)`を
// `Array.apply(null, Array(length * 2 - 1))`に変更
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment