typescript/school/palindrome.ts · 546 字节 · 下载原文
// 回文判定 —— 经典字符串练习
// Palindrome detection -- the classic string exercise
//
// 来源 / Source: Rosetta Code「Palindrome detection」JavaScript 条目(GFDL 1.2 / CC-BY-SA 3.0)
function isPalindrome(s: string): boolean {
return s === s.split("").reverse().join("");
}
const words: string[] = ["ingirumimusnocteetconsumimurigni", "racecar", "hello", "abba"];
for (let i: number = 0; i < words.length; i++) {
if (isPalindrome(words[i])) {
println_int(1);
} else {
println_int(0);
}
}