2024-07-07 22:14:17 +00:00
|
|
|
type SplitOperatorType = 'symbol' | 'regex';
|
|
|
|
|
|
|
|
|
|
export function reverseList(
|
2024-07-09 23:38:29 +01:00
|
|
|
splitOperatorType: SplitOperatorType,
|
|
|
|
|
splitSeparator: string,
|
|
|
|
|
joinSeparator: string = '\n',
|
|
|
|
|
input: string
|
2024-07-07 22:14:17 +00:00
|
|
|
): string {
|
2024-07-09 23:38:29 +01:00
|
|
|
let array: string[] = [];
|
|
|
|
|
switch (splitOperatorType) {
|
|
|
|
|
case 'symbol':
|
|
|
|
|
array = input.split(splitSeparator);
|
|
|
|
|
break;
|
|
|
|
|
case 'regex':
|
|
|
|
|
array = input
|
|
|
|
|
.split(new RegExp(splitSeparator))
|
|
|
|
|
.filter((item) => item !== '');
|
|
|
|
|
break;
|
|
|
|
|
}
|
2024-07-07 22:14:17 +00:00
|
|
|
|
2024-07-09 23:38:29 +01:00
|
|
|
const reversedList = array.reverse();
|
|
|
|
|
return reversedList.join(joinSeparator);
|
2024-07-07 22:14:17 +00:00
|
|
|
}
|