Skip to content

Commit baf1457

Browse files
committed
improvements to zero-padding
Optimized code for matching leading zeros in padded strings.
1 parent c62ffb7 commit baf1457

File tree

3 files changed

+278
-279
lines changed

3 files changed

+278
-279
lines changed

examples.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ const time = new Time();
99
* $ node examples.js
1010
*/
1111

12-
function toRange(min, max) {
12+
const toRange = (min, max) => {
1313
let key = 'to-range' + min + max;
1414
time.start(key);
15-
let str = toRegexRange(min, max, { wrap: false });
15+
1616
return [
1717
'',
18-
'`toRegexRange(\'' + min + ', ' + max + '\')`',
19-
'`' + str.split('|').join('\\|') + '`',
20-
'_' + time.end(key) + '_',
18+
`\`toRegexRange(${min}, ${max})\``,
19+
`\`${toRegexRange(min, max, { wrap: false }).split('|').join('\\|')}\``,
20+
`_${time.end(key)}_`,
2121
''
2222
];
23-
}
23+
};
2424

2525
toRange('1', '3');
2626

@@ -30,22 +30,24 @@ let rows = [
3030
];
3131

3232
let examples = [
33-
// ['0001', '5555'],
34-
// ['1', '5555'],
35-
// ['1', '555'],
36-
// ['1', '55'],
37-
// ['1', '50'],
38-
39-
['5', '5'],
40-
['5', '6'],
41-
['29', '51'],
42-
['31', '877'],
43-
['111', '555'],
4433
['-10', '10'],
4534
['-100', '-10'],
4635
['-100', '100'],
36+
4737
['001', '100'],
38+
['001', '555'],
4839
['0010', '1000'],
40+
41+
['1', '50'],
42+
['1', '55'],
43+
['1', '555'],
44+
['1', '5555'],
45+
['111', '555'],
46+
['29', '51'],
47+
['31', '877'],
48+
49+
['5', '5'],
50+
['5', '6'],
4951
['1', '2'],
5052
['1', '5'],
5153
['1', '10'],
@@ -55,7 +57,7 @@ let examples = [
5557
['1', '100000'],
5658
['1', '1000000'],
5759
['1', '10000000'],
58-
].forEach(function(args) {
60+
].forEach(args => {
5961
rows.push(toRange.apply(null, args));
6062
});
6163

@@ -67,8 +69,7 @@ console.log(text);
6769
* by verb and used in the .verb.md readme template
6870
*/
6971

70-
module.exports = function() {
71-
return text.split('\n').map(function(line) {
72-
return line.replace(/^ +/, '');
73-
}).join('\n');
72+
module.exports = () => {
73+
return text.split('\n').map(line => line.replace(/^ +/, '')).join('\n');
7474
};
75+

0 commit comments

Comments
 (0)