/**
* Reverse a string using built‑in methods.
* Types are explicit for clarity.
*/
function reverseString(str: string): string {
return str.split("").reverse().join("");
}
/**
* Measure the time it takes to run a function.
* Uses console timers for quick debugging.
*/
function timeFunction(label: string, fn: (arg: string) => string, arg: string): string {
console.time(label); // start timing
const result: string = fn(arg);
console.timeEnd(label); // end timing and print duration
return result;
}
// Run the measurement
const output: string = timeFunction("function test", reverseString, "A String");
console.log("Result:", output);
/*
run:
function test: 0.023ms
Result: gnirtS A
*/