Skip to content

Instantly share code, notes, and snippets.

View panarch's full-sized avatar
🎯
Focusing

Taehoon Moon panarch

🎯
Focusing
  • GlueSQL
  • Seoul, Korea
View GitHub Profile
@panarch
panarch / pick_2_items.js
Last active March 13, 2020 21:12
[JavaScript] Pick k items over size n array (nCk) - using Generator and flatMap
const items = ['Foo', 'Bar', 'Dog', 'Cat', 'Tea'];
const indexes = [0, 1, 2, 3, 4];
console.log('');
console.log('-------------------');
console.log('Pick 2 items using flatMap');
const picked = indexes.flatMap(i =>
indexes
.slice(i + 1)
.map(j => [items[i], items[j]])