Pages

Learn !

 

  1. function code (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(code('a', 'z')); oh !
  7. console.log(code('a', 'z', 3));
  8. console.log(code('c', 'h', 2)); // oh ! 



function code(start, end, step = 1) { const res = []; const startCode = start.charCodeAt(0); const endCode = end.charCodeAt(0); for (let c = startCode; c <= endCode; c += step) { res.push(String.fromCharCode(c)); } return res; }
function code(start, end, step = 1) { const res = []; const startCode = start.charCodeAt(0); const endCode = end.charCodeAt(0); for (let c = startCode; c <= endCode; c += step) { res.push(String.fromCharCode(c)); } return res; }