JS Snippets: String: Difference between revisions
From WikiMLT
m Стадий: 4 [Фаза:Авторизиране, Статус:Разработен]; Категория:JavaScript |
m Стадий: 5 [Фаза:Утвърждаване, Статус:Авторизиран]; Категория:JavaScript |
||
Line 62: | Line 62: | ||
{{devStage | {{devStage | ||
| Прндл = JavaScript | | Прндл = JavaScript | ||
| Стадий = | | Стадий = 5 | ||
| Фаза = | | Фаза = Утвърждаване | ||
| Статус = | | Статус = Авторизиран | ||
| ИдтПт = Spas | | ИдтПт = Spas | ||
| РзбПт = Spas | | РзбПт = Spas | ||
| АвтПт = {{REVISIONUSER}} | | АвтПт = Spas | ||
| УтвПт = {{REVISIONUSER}} | |||
| ИдтДт = 11.03.2023 | | ИдтДт = 11.03.2023 | ||
| РзбДт = 11.03.2023 | | РзбДт = 11.03.2023 | ||
| АвтДт = {{Today}} | | АвтДт = 11.03.2023 | ||
| УтвДт = {{Today}} | |||
| ИдтРв = [[Special:Permalink/32386|32386]] | | ИдтРв = [[Special:Permalink/32386|32386]] | ||
| РзбРв = [[Special:Permalink/32389|32389]] | | РзбРв = [[Special:Permalink/32389|32389]] | ||
| АвтРв = {{REVISIONID}} | | АвтРв = [[Special:Permalink/32391|32391]] | ||
| УтвРв = {{REVISIONID}} | |||
}} | }} | ||
</div> | </div> | ||
</noinclude> | </noinclude> |
Revision as of 12:34, 11 March 2023
References
Reverse a String
function reverse(str: string) {
return str.split("").reverse().join("");
}
function reverse(str: string) {
let newStr = "";
for (let i = str.length - 1; i >= 0; i--) newStr += str[i];
return newStr;
}
Is Palindrome
- Palindromes are words that are the same forward or backward.
function isPalindrome(str: string) {
return str === str.split("").reverse().join("");
}
Is Anagram
- Anagrams are groups of words that can be spelled with the same letters.
function isAnagram(str1: string, str2: string) {
if (str1.length !== str2.length) return false;
return str1.split("").sort().join("") === str2.split("").sort().join("");
}
Title Case
- Write a function that will capitalize every word in a sentence.
function capitalizeWord(word: string) {
return word[0].toUpperCase() + word.slice(1);
}
function toTitleCase(str: string) {
return str.split(" ").map(word => capitalizeWord(word)).join(" ");
}
console.log(toTitleCase("pumpkin pranced purposefully across the pond"));
Pumpkin Pranced Purposefully Across The Pond