mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-16 05:00:59 +08:00
28 lines
579 B
TypeScript
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));
|