Iterator should print every value within range but its only printing alternate nos.
function iterator(rangeStart, rangeEnd) {
  if (rangeStart == 0 && rangeEnd == 0) {
    return null;
  }
  var iterate = function*(start = 0, end = 5, step = 1) {
    let iterationcount = 0;
    for (let i = start; i <= end; i += step) {
      yield i;
      iterationCount = i;
    }
    return iterationCount;
  }
  var values = iterate(rangeStart, rangeEnd);
  var tmp = [];
  while (values.next().value != undefined) {
    tmp.push(values.next().value);
  }
  return tmp.join(",");
}
console.log(iterator(0, 10))expected
[0,1,2,3,4,5,6,7,8,9,10]
Result
[1,3,5,7,9,10]
 
                        
Every call to
nextwill consume a value from the iterator, so thewhilecondition is consuming a value that will therefore not get intotmp.But... JavaScript allows you to consume values in much easier ways. For instance with
Array.fromor spread syntax you can collect all values from the iterator into an array.Not your question, but:
iterationCountserves no purpose in your code, so just drop that part.ifstatement.iteratorfor your function is somewhat misleading, as the return value is not an iterator, but a comma separated string. I would therefore call itrangeToCsv