Skip to content

Commit cd5bd1c

Browse files
committed
Remove dead code on ord (thanks incidence!); simplify ord/chr
1 parent 50e48a1 commit cd5bd1c

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

functions/strings/chr.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,5 @@ function chr (codePt) {
1414
codePt -= 0x10000;
1515
return String.fromCharCode(0xD800 + (codePt >> 10), 0xDC00 + (codePt & 0x3FF));
1616
}
17-
else {
18-
return String.fromCharCode(codePt);
19-
}
17+
return String.fromCharCode(codePt);
2018
}

functions/strings/ord.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,19 @@ function ord (string) {
33
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
44
// + bugfixed by: Onno Marsman
55
// + improved by: Brett Zamir (http://brett-zamir.me)
6+
// + input by: incidence
67
// * example 1: ord('K');
78
// * returns 1: 75
89
// * example 2: ord('\uD800\uDC00'); // surrogate pair to create a single Unicode character
910
// * returns 2: 65536
1011

11-
var str = string + '';
12-
13-
var code = str.charCodeAt(0);
12+
var str = string + '',
13+
code = str.charCodeAt(0);
1414
if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
1515
var hi = code;
1616
if (str.length === 1) {
1717
return code; // This is just a high surrogate with no following low surrogate, so we return its value;
1818
// we could also throw an error as it is not a complete character, but someone may want to know
19-
}
20-
var low = str.charCodeAt(1);
21-
if (!low) {
22-
2319
}
2420
return ((hi - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;
2521
}

0 commit comments

Comments
 (0)