Sign in

Javascript’s generator functions are powerful programing constructs that allows you to “pause” your code execution flow in order to “yield” some computation results to the callers. It is especially useful as a functional way to implement iterators.

In this article, we will illustrate how we can use recursive generator functions to produce an iterator for array combinations. We will first see how to generate n-combinations, and then we will move on to generating all combinations.

Generating n-Combinations

Consider the following array:

We are interested in writing an n-combination iterator function combinationN(), which should produce…

Fei Xie

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store