created by aha00a at 2019-07-22
last modified by aha00a at 2020-11-11
revision: 3

JavaScript slidng grouped

https://jsfiddle.net/aha00a/emgh4uox/13/

없길래 직접 만들어봄. 다만 groupedLodashchunk(github)하고 같은 거라고 함. --2019-07-22

1. sliding

const sliding = (array, size) => array.map((v, i, a) => a.slice(i, i + size)).filter(v => v.length === size);
  • example
    • sliding(range(0, 10), 4)
      [[0,1,2,3],[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7],[5,6,7,8],[6,7,8,9]]

2. grouped

const grouped = (array, size) => array.map((v, i, a) => i % size ? null : a.slice(i, i + size)).filter(v => v);
  • example
    • grouped(range(0, 10), 2)
      [[0,1],[2,3],[4,5],[6,7],[8,9]]
    • grouped(range(0, 10), 3)
      [[0,1,2],[3,4,5],[6,7,8],[9]]

3. See Also

3.2. Similar Pages

Similar pages by cosine similarity. Words after page name are term frequency.

3.3. Adjacent Pages