I need to refactor some code for a project, but we've decided internally not to use generators. I found this code snippet that looks unnecessary to me since it doesn't seem to require a generator at all. How can I convert it into a regular function without using generators (as far as I know, there are no async operations)?
Just to clarify, I'm looking to remove generators from this specific piece of code.
Code:
const getResults = (totalData) => {
const combinations = totalData.reduce((a, b) => a * b.length, 1);
return function() {
for (let i = 0; i < combinations; i++) {
yield createSolution(i, totalData);
}
return null;
}
}
This is how the function is called:
const result = getResults(obj.elementsInObj);
for (let data of result()) {
const resolve = validateData(data, obj.elementsInObj);
if (resolve) {
return resolve;
}
}