Skip to content

Commit 7b8e58f

Browse files
Merge pull request #49 from Axorax/main
Add more JavaScript snippets
2 parents 22ce5fe + 7218bed commit 7b8e58f

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

public/data/javascript.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,49 @@
141141
],
142142
"tags": ["javascript", "data", "utility"],
143143
"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"
144187
}
145188
]
146189
},

0 commit comments

Comments
 (0)