title: Opposite of Array.reduce() in javascript
body: <p>Array.reduce() takes an array and combines elements from the array with an accumulator until all the elements are consumed.</p>
  
  <p>Is there a function (often called "unfold" in other languages) that starts with a value and keeps generating elements until a complete array is produced (the accumulator is depleted)?</p>
  
  <p>I am trying to do this as part of converting between arbitrary bases.  The code as I have it is as follows, but I would like to eliminate the raw loop.</p>
  
  <pre><code>var dstAlphabet = "0123456789ABCDEFGH";
  var dstBase = dstAlphabet.length;
  var wet = BigInteger(100308923948716816384684613592839);
  var digits_reversed = [];
  while (wet.isPositive())
  {
    // var digitVal = wet % dstBase
    var divRem = wet.divRem(dstBase); // [result of division, remainder]
    wet = divRem[0];
    digits_reversed.push(dstAlphabet.charAt(divRem[1].toJSValue()));
  }
  
  return digits_reversed.reverse().join("");
  </code></pre>