A very good usecase for generators:
function* sum(target, numbers, previous = []) {
if(target === 0) yield previous;
if(target <= 0) return;
for(const n of numbers)
yield* sum(target - n, numbers, [...previous, n]);
}
More Related Contents:
- How can I use Unicode-aware regular expressions in JavaScript?
- __proto__ VS. prototype in JavaScript
- AJAX cross domain call
- What is the difference between string primitives and String objects in JavaScript?
- What does a tilde do when it precedes an expression?
- How to detect a textbox’s content has changed
- ES2015 import doesn’t work (even at top-level) in Firefox
- How to fix jslint error ‘Don’t make functions within a loop.’?
- How does += (plus equal) work?
- How to sort numbers correctly with Array.sort()? [duplicate]
- offsetting an html anchor to adjust for fixed header [duplicate]
- Javascript – convert array of arrays into array of objects with prefilled values
- Node-style require for in-browser javascript? [closed]
- jQuery jqGrid Show message when an edit row is complete
- What are the js recursion limits for Firefox, Chrome, Safari, IE, etc?
- Open a new javascript window(.open) along with its CSS styling
- How to use google.maps.event.trigger(map, ‘resize’)
- option.style.display = “none” not working in safari [duplicate]
- How to recall or restart MathJax?
- Lat Long to X Y Z position in JS .. not working
- Run multiple recursive Promises and break when requested
- Javascript: How to generate formatted easy-to-read JSON straight from an object? [duplicate]
- Converting an image to base64 in angular 2
- How should I import the Spatial Illusions milsymbol library into my webpage?
- Does every object in JS have a toString() method?
- react-router (v4) how to go back?
- Use PHP code in external Javascript file
- Converting string array to Name/Value object in javascript
- How can I dispatch function in redux?
- Proper way to remove all series data from a highcharts chart?