From 358ad8c0db8185e4db76e49af39f2f0024779439 Mon Sep 17 00:00:00 2001 From: Axorax Date: Tue, 31 Dec 2024 14:10:32 +0600 Subject: [PATCH 1/2] Add more JavaScript snippets --- public/data/javascript.json | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/public/data/javascript.json b/public/data/javascript.json index f50cd4c4..9ec9b8ab 100644 --- a/public/data/javascript.json +++ b/public/data/javascript.json @@ -141,6 +141,63 @@ ], "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": "Trim a String to a Specified Length", + "description": "Trims a string to a specified length and appends '...' if it exceeds that length.", + "code": [ + "function trimString(str, maxLength) {", + " return str.length > maxLength ? str.slice(0, maxLength) + '...' : str;", + "}", + "", + "// Example usage:", + "console.log(trimString('Hello, world!', 5)); // Output: 'Hello...'" + ], + "tags": ["string", "javascript", "trim"], + "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" } ] }, From 7218bed0f45eb87be2abf95da90332be13980caa Mon Sep 17 00:00:00 2001 From: Axorax Date: Tue, 31 Dec 2024 16:09:27 +0600 Subject: [PATCH 2/2] fix --- public/data/javascript.json | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/public/data/javascript.json b/public/data/javascript.json index 9ec9b8ab..9e8877e3 100644 --- a/public/data/javascript.json +++ b/public/data/javascript.json @@ -171,20 +171,6 @@ "tags": ["string", "manipulation", "word count", "count"], "author": "axorax" }, - { - "title": "Trim a String to a Specified Length", - "description": "Trims a string to a specified length and appends '...' if it exceeds that length.", - "code": [ - "function trimString(str, maxLength) {", - " return str.length > maxLength ? str.slice(0, maxLength) + '...' : str;", - "}", - "", - "// Example usage:", - "console.log(trimString('Hello, world!', 5)); // Output: 'Hello...'" - ], - "tags": ["string", "javascript", "trim"], - "author": "axorax" - }, { "title": "Remove All Whitespace", "description": "Removes all whitespace from a string.",