Files
scriptc/tests/corpus/402-string-functions.ts
2026-07-22 18:08:04 -05:00

28 lines
579 B
TypeScript

function greet(who: string): string {
return "hi " + who;
}
function shout(msg: string): string {
return msg + "!";
}
function repeat(s: string, times: number): string {
let out = "";
for (let i = 0; i < times; i = i + 1) {
out = out + s;
}
return out;
}
console.log(shout(greet("world")));
console.log(repeat("ab", 4));
console.log(repeat(greet("x"), 2));
function describe(n: number): string {
if (n < 0) {
return "negative";
}
if (n === 0) {
return "zero";
}
return `positive (${n})`;
}
console.log(describe(-5), describe(0), describe(42));