diff --git a/public/data/javascript.json b/public/data/javascript.json index f50cd4c4..9e8877e3 100644 --- a/public/data/javascript.json +++ b/public/data/javascript.json @@ -141,6 +141,49 @@ ], "tags": ["javascript", "data", "utility"], "author": "realvishalrana" + }, + { + "title": "Check if String is a Palindrome", + "description": "Checks whether a given string is a palindrome.", + "code": [ + "function isPalindrome(str) {", + " const cleanStr = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();", + " return cleanStr === cleanStr.split('').reverse().join('');", + "}", + "", + "// Example usage:", + "console.log(isPalindrome('A man, a plan, a canal, Panama')); // Output: true" + ], + "tags": ["javascript", "check", "palindrome", "string"], + "author": "axorax" + }, + { + "title": "Count Words in a String", + "description": "Counts the number of words in a string.", + "code": [ + "function countWords(str) {", + " return str.trim().split(/\\s+/).length;", + "}", + "", + "// Example usage:", + "console.log(countWords('Hello world! This is a test.')); // Output: 6" + ], + "tags": ["string", "manipulation", "word count", "count"], + "author": "axorax" + }, + { + "title": "Remove All Whitespace", + "description": "Removes all whitespace from a string.", + "code": [ + "function removeWhitespace(str) {", + " return str.replace(/\\s+/g, '');", + "}", + "", + "// Example usage:", + "console.log(removeWhitespace('Hello world!')); // Output: 'Helloworld!'" + ], + "tags": ["string", "whitespace"], + "author": "axorax" } ] },