reverse tool (easiest) and testCases then updated index file

This commit is contained in:
Chesterkxng
2024-07-07 22:14:17 +00:00
parent b11540b016
commit 6774943196
5 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
type SplitOperatorType = 'symbol' | 'regex';
export function reverseList(
splitOperatorType: SplitOperatorType,
splitSeparator: string,
joinSeparator: string = '\n',
input: string,
): string {
let array: string[] = [];
switch (splitOperatorType) {
case 'symbol':
array = input.split(splitSeparator);
break;
case 'regex':
array = input.split(new RegExp(splitSeparator)).filter(item => item !== '');
break;
}
const reversedList = array.reverse();
return reversedList.join(joinSeparator);
}