手写创建26个大小写字母

返回大小写的26个字母表数组

function alphabet(str) {
  return Array(26).fill(1,0,26).map((el,index) => { 
    return String.fromCharCode((el,index + str.charCodeAt(0)))
  })
}
console.log(alphabet('A'));
console.log(alphabet('a'));

返回指定顺序的字母表数组


function rangeAlphabet(a,b) {
  const range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step));
  return range(a.charCodeAt(0), b.charCodeAt(0), 1).map(x => String.fromCharCode(x));
}

console.log(rangeAlphabet('c','g'));

posted @ 2022-03-10 10:43  怕浪小乌龟  阅读(95)  评论(0编辑  收藏  举报