|
141 | 141 | ],
|
142 | 142 | "tags": ["javascript", "data", "utility"],
|
143 | 143 | "author": "realvishalrana"
|
| 144 | + }, |
| 145 | + { |
| 146 | + "title": "Check if String is a Palindrome", |
| 147 | + "description": "Checks whether a given string is a palindrome.", |
| 148 | + "code": [ |
| 149 | + "function isPalindrome(str) {", |
| 150 | + " const cleanStr = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();", |
| 151 | + " return cleanStr === cleanStr.split('').reverse().join('');", |
| 152 | + "}", |
| 153 | + "", |
| 154 | + "// Example usage:", |
| 155 | + "console.log(isPalindrome('A man, a plan, a canal, Panama')); // Output: true" |
| 156 | + ], |
| 157 | + "tags": ["javascript", "check", "palindrome", "string"], |
| 158 | + "author": "axorax" |
| 159 | + }, |
| 160 | + { |
| 161 | + "title": "Count Words in a String", |
| 162 | + "description": "Counts the number of words in a string.", |
| 163 | + "code": [ |
| 164 | + "function countWords(str) {", |
| 165 | + " return str.trim().split(/\\s+/).length;", |
| 166 | + "}", |
| 167 | + "", |
| 168 | + "// Example usage:", |
| 169 | + "console.log(countWords('Hello world! This is a test.')); // Output: 6" |
| 170 | + ], |
| 171 | + "tags": ["string", "manipulation", "word count", "count"], |
| 172 | + "author": "axorax" |
| 173 | + }, |
| 174 | + { |
| 175 | + "title": "Remove All Whitespace", |
| 176 | + "description": "Removes all whitespace from a string.", |
| 177 | + "code": [ |
| 178 | + "function removeWhitespace(str) {", |
| 179 | + " return str.replace(/\\s+/g, '');", |
| 180 | + "}", |
| 181 | + "", |
| 182 | + "// Example usage:", |
| 183 | + "console.log(removeWhitespace('Hello world!')); // Output: 'Helloworld!'" |
| 184 | + ], |
| 185 | + "tags": ["string", "whitespace"], |
| 186 | + "author": "axorax" |
144 | 187 | }
|
145 | 188 | ]
|
146 | 189 | },
|
|
0 commit comments