reverse tool, testCases then updated index file

This commit is contained in:
Chesterkxng
2024-07-11 00:01:59 +00:00
parent c48b2853b6
commit 0064476c51
5 changed files with 108 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
import { reverseString } from 'utils/string';
export function stringReverser(
input: string,
multiLine: boolean,
emptyItems: boolean,
trim: boolean
) {
let array: string[] = [];
let result: string[] = [];
// split the input in multiLine mode
if (multiLine) {
array = input.split('\n');
}
else {
array.push(input);
}
// handle empty items
if (emptyItems){
array = array.filter(Boolean);
}
// Handle trim
if (trim) {
array = array.map(line => line.trim());
}
result = array.map(element => reverseString(element));
return result.join('\n');
}