Pages

Map en action


  1. function alphabetRange (start, end, step = 1) {
  2.   return new Array(Math.ceil((end.charCodeAt(0) - start.charCodeAt(0))/step))
  3.   .fill(start.charCodeAt(0))
  4.   .map((x, i) => String.fromCharCode(i*step + start.charCodeAt(0)));
  5. }

  6. console.log(alphabetRange('c', 'h', 2));