main
Last change
on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
776 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var GetIntrinsic = require('get-intrinsic');
|
---|
4 | var callBound = require('call-bind/callBound');
|
---|
5 |
|
---|
6 | var $fromCharCode = GetIntrinsic('%String.fromCharCode%');
|
---|
7 | var $TypeError = require('es-errors/type');
|
---|
8 | var $charCodeAt = callBound('String.prototype.charCodeAt');
|
---|
9 | var $push = callBound('Array.prototype.push');
|
---|
10 |
|
---|
11 | module.exports = function CharacterRange(A, B) {
|
---|
12 | if (A.length !== 1 || B.length !== 1) {
|
---|
13 | throw new $TypeError('Assertion failed: CharSets A and B contain exactly one character');
|
---|
14 | }
|
---|
15 |
|
---|
16 | var a = A[0];
|
---|
17 | var b = B[0];
|
---|
18 |
|
---|
19 | var i = $charCodeAt(a, 0);
|
---|
20 | var j = $charCodeAt(b, 0);
|
---|
21 |
|
---|
22 | if (!(i <= j)) {
|
---|
23 | throw new $TypeError('Assertion failed: i is not <= j');
|
---|
24 | }
|
---|
25 |
|
---|
26 | var arr = [];
|
---|
27 | for (var k = i; k <= j; k += 1) {
|
---|
28 | $push(arr, $fromCharCode(k));
|
---|
29 | }
|
---|
30 | return arr;
|
---|
31 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.