2018-10-04 14:37:37 +01:00
---
title: Generate lower case ASCII alphabet
id: 5a23c84252665b21eecc7e7a
challengeType: 5
2019-08-05 09:17:33 -07:00
forumTopicId: 302274
2018-10-04 14:37:37 +01:00
---
## Description
<section id='description'>
2019-03-05 14:39:16 +09:00
Write a function to generate an array of lower case ASCII characters for a given range. For example, given the range <code>['a', 'd']</code>, the function should return <code>['a', 'b', 'c', 'd']</code>.
2018-10-04 14:37:37 +01:00
</section>
## Instructions
<section id='instructions'>
</section>
## Tests
<section id='tests'>
```yml
tests:
2018-10-08 12:52:10 +01:00
- text: <code>lascii</code> should be a function.
2019-07-26 05:24:52 -07:00
testString: assert(typeof lascii=='function');
2018-10-08 12:52:10 +01:00
- text: <code>lascii("a","d")</code> should return an array.
2019-07-26 05:24:52 -07:00
testString: assert(Array.isArray(lascii('a','d')));
2018-10-20 21:02:47 +03:00
- text: "<code>lascii('a','d')</code> should return <code>[ 'a', 'b', 'c', 'd' ]</code>."
2019-07-26 05:24:52 -07:00
testString: assert.deepEqual(lascii("a","d"),results[0]);
2018-10-20 21:02:47 +03:00
- text: <code>lascii('c','i')</code> should return <code>[ 'c', 'd', 'e', 'f', 'g', 'h', 'i' ]</code>.
2019-07-26 05:24:52 -07:00
testString: assert.deepEqual(lascii("c","i"),results[1]);
2018-10-20 21:02:47 +03:00
- text: <code>lascii('m','q')</code> should return <code>[ 'm', 'n', 'o', 'p', 'q' ]</code>.
2019-07-26 05:24:52 -07:00
testString: assert.deepEqual(lascii("m","q"),results[2]);
2018-10-20 21:02:47 +03:00
- text: <code>lascii('k','n')</code> should return <code>[ 'k', 'l', 'm', 'n' ]</code>.
2019-07-26 05:24:52 -07:00
testString: assert.deepEqual(lascii("k","n"),results[3]);
2018-10-20 21:02:47 +03:00
- text: <code>lascii('t','z')</code> should return <code>[ 't', 'u', 'v', 'w', 'x', 'y', 'z' ]</code>.
2019-07-26 05:24:52 -07:00
testString: assert.deepEqual(lascii("t","z"),results[4]);
2018-10-04 14:37:37 +01:00
```
</section>
## Challenge Seed
<section id='challengeSeed'>
<div id='js-seed'>
```js
2019-03-05 14:39:16 +09:00
function lascii(cFrom, cTo) {
2020-09-15 09:57:40 -07:00
2018-10-04 14:37:37 +01:00
}
```
</div>
### After Test
<div id='js-teardown'>
```js
2018-10-20 21:02:47 +03:00
let results=[
[ 'a', 'b', 'c', 'd' ],
[ 'c', 'd', 'e', 'f', 'g', 'h', 'i' ],
[ 'm', 'n', 'o', 'p', 'q' ],
[ 'k', 'l', 'm', 'n' ],
[ 't', 'u', 'v', 'w', 'x', 'y', 'z' ]
]
2018-10-04 14:37:37 +01:00
```
</div>
</section>
## Solution
<section id='solution'>
```js
function lascii(cFrom, cTo) {
function cRange(cFrom, cTo) {
var iStart = cFrom.charCodeAt(0);
return Array.apply(
null, Array(cTo.charCodeAt(0) - iStart + 1)
).map(function (_, i) {
return String.fromCharCode(iStart + i);
});
}
return cRange(cFrom, cTo);
}
```
</section>