我正在寻求一些帮助来生成所选座位号列表。
A | B | C | D | E | F |
---|---|---|---|---|---|
A1 | A2 | A3 | A4 | A5 | A6 |
B7 | B8 | B9 | B10 | B11 | B12 |
C13 | C14 | C15 | C16 | C17 | C18 |
D19 | D20 | D21 | D22 | D23 | D24 |
E25 | E26 | E27 | E28 | E29 | E30 |
F31 | F32 | F33 | F34 | F35 | F36 |
G37 | G38 | G39 | G40 | G41 | G42 |
H43 | H44 | H45 | H46 | H47 | H48 |
I49 | I50 | I51 | I52 | I53 | I54 |
J55 | J56 | J57 | J58 | J59 | J60 |
上表是座位表。为了选择一些座位,我提供了一个输入字段,用户可以在其中输入座位编号范围,如
A1-B7
或选择单个座位,如 F31
示例:
A1-B7,H43-H45,F31
鉴于上述输入,我想提取所有座位并生成类似的顺序列表
输出:
['A1','A2','A3','A4','A5','A6','B7','F31','H43','H44','H45']
1)我想使用正则表达式分割输入值 2)如果范围生成选择的范围 3)对字母数字列表进行排序
第一步:
**正则表达式:**我对正则表达式不熟悉。
I need help here to extract using regex range and individual select seats.
第二步:
范围选定列表:从步骤if范围我将得到一个数组开始和结束['A1','B7']。
How I loop though a alphanumeric range?
第三步:
对字母数字数组进行排序:我知道如何对整数而不是字母数字数组进行排序。
I need help to sort alphanumeric array
您必须解析输入。 这是一些伪代码:
function extractSeats(input) {
const seats = seatsInput.split(',');
seats.reduce((extractedSeats, seatInput) => {
if (seatInput.includes(",")) {
const [start, end] = seatInput.split('-');
//get start-letter and start-number
//get end-letter and end-number
//produce the range and add it to extractedSeats
}
else {
extractedSeats.push(seatInput);
}
return extractedSeats;
});
}