From 43cac96224203c5b03cfd9ee727b72d5a8c2e651 Mon Sep 17 00:00:00 2001 From: JanluOfficial <95766563+JanluOfficial@users.noreply.github.com> Date: Fri, 10 Jan 2025 19:21:45 +0100 Subject: [PATCH 1/9] Validation Functions --- .../validation/validate-a-credit-card-number.md | 16 ++++++++++++++++ snippets/javascript/validation/validate-a-url.md | 16 ++++++++++++++++ .../validation/validate-a-us-phone-number.md | 16 ++++++++++++++++ .../validation/validate-an-email-adress.md | 16 ++++++++++++++++ .../validate-an-international-phone-number.md | 16 ++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 snippets/javascript/validation/validate-a-credit-card-number.md create mode 100644 snippets/javascript/validation/validate-a-url.md create mode 100644 snippets/javascript/validation/validate-a-us-phone-number.md create mode 100644 snippets/javascript/validation/validate-an-email-adress.md create mode 100644 snippets/javascript/validation/validate-an-international-phone-number.md diff --git a/snippets/javascript/validation/validate-a-credit-card-number.md b/snippets/javascript/validation/validate-a-credit-card-number.md new file mode 100644 index 00000000..6eb0f09e --- /dev/null +++ b/snippets/javascript/validation/validate-a-credit-card-number.md @@ -0,0 +1,16 @@ +--- +title: Validate a Credit Card Number +description: Validates a Credit Card Number for a variety of major international credit card formats, including Visa, MasterCard, American Expres, Diners Club and JCB. +author: JanluOfficial +tags: validation,url +--- + +```js +function validateCreditCardNumber(cardNumber) { + const cardRegex = /^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|6(?:011|5[0-9]{2})[0-9]{12}|(?:2131|1800|35\d{3})\d{11})$/; + return cardRegex.test(cardNumber); +} + +// Usage: +validateCreditCardNumber("4111111111111111"); // Returns: true +``` diff --git a/snippets/javascript/validation/validate-a-url.md b/snippets/javascript/validation/validate-a-url.md new file mode 100644 index 00000000..cc6234db --- /dev/null +++ b/snippets/javascript/validation/validate-a-url.md @@ -0,0 +1,16 @@ +--- +title: Validate a URL +description: Validates a URL. +author: JanluOfficial +tags: validation,url +--- + +```js +function validateURL(url) { + const urlRegex = /^(https?|http?|ftp):\/\/[^\s/$.?#].[^\s]*$/i; + return urlRegex.test(url); +} + +// Usage: +validateURL("https://www.example.com"); // Returns: true +``` diff --git a/snippets/javascript/validation/validate-a-us-phone-number.md b/snippets/javascript/validation/validate-a-us-phone-number.md new file mode 100644 index 00000000..6a141c13 --- /dev/null +++ b/snippets/javascript/validation/validate-a-us-phone-number.md @@ -0,0 +1,16 @@ +--- +title: Validate a US Phone Number +description: Validates a phone number from the United States of America. +author: JanluOfficial +tags: validation,phone,united-states +--- + +```js +function validateUSPhoneNumber(phoneNumber) { + const phoneRegex = /^\(?([0-9]{3})\)?[-. ]?([0-9]{3})[-. ]?([0-9]{4})$/; + return phoneRegex.test(phoneNumber); +} + +// Usage: +validateUSPhoneNumber("123-456-7890"); // Returns: true +``` diff --git a/snippets/javascript/validation/validate-an-email-adress.md b/snippets/javascript/validation/validate-an-email-adress.md new file mode 100644 index 00000000..a3d9204a --- /dev/null +++ b/snippets/javascript/validation/validate-an-email-adress.md @@ -0,0 +1,16 @@ +--- +title: Validate an Email Adress +description: Validates an Email Adress +author: JanluOfficial +tags: validation,email +--- + +```js +function validateEmail(email) { + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return emailRegex.test(email); +} + +// Usage: +validateEmail("test@example.com"); // Returns: true +``` diff --git a/snippets/javascript/validation/validate-an-international-phone-number.md b/snippets/javascript/validation/validate-an-international-phone-number.md new file mode 100644 index 00000000..04e7a4c5 --- /dev/null +++ b/snippets/javascript/validation/validate-an-international-phone-number.md @@ -0,0 +1,16 @@ +--- +title: Validate an international Phone Number +description: Validates an international Phone Number. +author: JanluOfficial +tags: validation,phone,international +--- + +```js +function validateInternationalPhoneNumber(phoneNumber) { + const phoneRegex = /^\+?[1-9]\d{1,14}$/; + return phoneRegex.test(phoneNumber); +} + +// Usage: +validateInternationalPhoneNumber("+1234567890"); // Returns: true +``` From e1238671340556e4a115d018740b2419e3524e34 Mon Sep 17 00:00:00 2001 From: JanluOfficial <95766563+JanluOfficial@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:38:08 +0100 Subject: [PATCH 2/9] Color Functions --- .../color-manipulation/hex-to-hsl-color.md | 55 +++++++++++++++++++ .../color-manipulation/hsl-to-hex-color.md | 42 ++++++++++++++ .../color-manipulation/random-hex-color.md | 15 +++++ .../color-manipulation/random-hsl-color.md | 18 ++++++ .../color-manipulation/random-rgb-color.md | 18 ++++++ 5 files changed, 148 insertions(+) create mode 100644 snippets/javascript/color-manipulation/hex-to-hsl-color.md create mode 100644 snippets/javascript/color-manipulation/hsl-to-hex-color.md create mode 100644 snippets/javascript/color-manipulation/random-hex-color.md create mode 100644 snippets/javascript/color-manipulation/random-hsl-color.md create mode 100644 snippets/javascript/color-manipulation/random-rgb-color.md diff --git a/snippets/javascript/color-manipulation/hex-to-hsl-color.md b/snippets/javascript/color-manipulation/hex-to-hsl-color.md new file mode 100644 index 00000000..82cfe22d --- /dev/null +++ b/snippets/javascript/color-manipulation/hex-to-hsl-color.md @@ -0,0 +1,55 @@ +--- +title: Hex to HSL Color +description: Converts HEX color values to HSL color values. +author: JanluOfficial +tags: validation,url +--- + +```js +function hexToHsl(hex) { + // Remove the '#' if present + hex = hex.replace(/^#/, ''); + + // Convert HEX to RGB + let r = parseInt(hex.substring(0, 2), 16) / 255; + let g = parseInt(hex.substring(2, 4), 16) / 255; + let b = parseInt(hex.substring(4, 6), 16) / 255; + + // Find the min, max, and delta + const max = Math.max(r, g, b); + const min = Math.min(r, g, b); + const delta = max - min; + + // Calculate Lightness + let l = (max + min) / 2; + + // Calculate Saturation + let s = 0; + if (delta !== 0) { + s = delta / (1 - Math.abs(2 * l - 1)); + } + + // Calculate Hue + let h = 0; + if (delta !== 0) { + if (max === r) { + h = ((g - b) / delta) % 6; + } else if (max === g) { + h = (b - r) / delta + 2; + } else if (max === b) { + h = (r - g) / delta + 4; + } + h = Math.round(h * 60); // Convert to degrees + if (h < 0) h += 360; + } + + // Convert saturation and lightness to percentages + s = +(s * 100).toFixed(2); + l = +(l * 100).toFixed(2); + + return { h, s, l }; +} + +// Usage: +hexToHsl("#3498db"); // Returns: { h: 204, s: 69.87, l: 53.14 } +``` \ No newline at end of file diff --git a/snippets/javascript/color-manipulation/hsl-to-hex-color.md b/snippets/javascript/color-manipulation/hsl-to-hex-color.md new file mode 100644 index 00000000..93805f38 --- /dev/null +++ b/snippets/javascript/color-manipulation/hsl-to-hex-color.md @@ -0,0 +1,42 @@ +--- +title: HSL to Hex Color +description: Converts HSL color values to HEX color values. +author: JanluOfficial +tags: validation,url +--- + +```js +function hslToHex(h, s, l) { + s /= 100; + l /= 100; + + let c = (1 - Math.abs(2 * l - 1)) * s; + let x = c * (1 - Math.abs((h / 60) % 2 - 1)); + let m = l - c / 2; + + let r = 0, g = 0, b = 0; + + if (0 <= h && h < 60) { + r = c; g = x; b = 0; + } else if (60 <= h && h < 120) { + r = x; g = c; b = 0; + } else if (120 <= h && h < 180) { + r = 0; g = c; b = x; + } else if (180 <= h && h < 240) { + r = 0; g = x; b = c; + } else if (240 <= h && h < 300) { + r = x; g = 0; b = c; + } else if (300 <= h && h < 360) { + r = c; g = 0; b = x; + } + + r = Math.round((r + m) * 255).toString(16).padStart(2, '0'); + g = Math.round((g + m) * 255).toString(16).padStart(2, '0'); + b = Math.round((b + m) * 255).toString(16).padStart(2, '0'); + + return `#${r}${g}${b}`; +} + +// Usage: +hslToHex(204, 69.87, 53.14); // Returns: "#3498db" +``` \ No newline at end of file diff --git a/snippets/javascript/color-manipulation/random-hex-color.md b/snippets/javascript/color-manipulation/random-hex-color.md new file mode 100644 index 00000000..85b51af9 --- /dev/null +++ b/snippets/javascript/color-manipulation/random-hex-color.md @@ -0,0 +1,15 @@ +--- +title: Random Hex Color +description: Generates a completely random hex color. +author: JanluOfficial +tags: color,hex,random +--- + +```js +function getRandomHexColor() { + return '#' + Math.floor(Math.random() * 16777215).toString(16).padStart(6, '0'); +} + +// Usage: +getRandomHexColor(); // Returns: "#RRGGBB" (random) +``` \ No newline at end of file diff --git a/snippets/javascript/color-manipulation/random-hsl-color.md b/snippets/javascript/color-manipulation/random-hsl-color.md new file mode 100644 index 00000000..ce4d1c6d --- /dev/null +++ b/snippets/javascript/color-manipulation/random-hsl-color.md @@ -0,0 +1,18 @@ +--- +title: Random HSL Color +description: Generates a completely random HSL color. +author: JanluOfficial +tags: color,hsl,random +--- + +```js +function getRandomHslColor() { + const h = Math.floor(Math.random() * 360); + const s = Math.floor(Math.random() * 101); + const l = Math.floor(Math.random() * 101); + return [h, s, l]; +} + +// Usage: +getRandomHslColor(); // Returns: (h, s, l) (random) +``` diff --git a/snippets/javascript/color-manipulation/random-rgb-color.md b/snippets/javascript/color-manipulation/random-rgb-color.md new file mode 100644 index 00000000..7414b8bb --- /dev/null +++ b/snippets/javascript/color-manipulation/random-rgb-color.md @@ -0,0 +1,18 @@ +--- +title: Random RGB Color +description: Generates a completely random RGB color. +author: JanluOfficial +tags: color,rgb,random +--- + +```js +function getRandomRgbColor() { + const r = Math.floor(Math.random() * 256); + const g = Math.floor(Math.random() * 256); + const b = Math.floor(Math.random() * 256); + return (r, g, b); +} + +// Usage: +getRandomRgbColor(); // Returns: (r, g, b) (random) +``` From a112313e9df122e4d7c5ac92cae25d3395f718eb Mon Sep 17 00:00:00 2001 From: JanluOfficial <95766563+JanluOfficial@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:46:22 +0100 Subject: [PATCH 3/9] Fix examples and returns on random-color snippets --- snippets/javascript/color-manipulation/random-hex-color.md | 2 +- snippets/javascript/color-manipulation/random-hsl-color.md | 4 ++-- snippets/javascript/color-manipulation/random-rgb-color.md | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/snippets/javascript/color-manipulation/random-hex-color.md b/snippets/javascript/color-manipulation/random-hex-color.md index 85b51af9..2b066a38 100644 --- a/snippets/javascript/color-manipulation/random-hex-color.md +++ b/snippets/javascript/color-manipulation/random-hex-color.md @@ -11,5 +11,5 @@ function getRandomHexColor() { } // Usage: -getRandomHexColor(); // Returns: "#RRGGBB" (random) +getRandomHexColor(); // Returns: "#f904d7" (random) ``` \ No newline at end of file diff --git a/snippets/javascript/color-manipulation/random-hsl-color.md b/snippets/javascript/color-manipulation/random-hsl-color.md index ce4d1c6d..d90938d0 100644 --- a/snippets/javascript/color-manipulation/random-hsl-color.md +++ b/snippets/javascript/color-manipulation/random-hsl-color.md @@ -10,9 +10,9 @@ function getRandomHslColor() { const h = Math.floor(Math.random() * 360); const s = Math.floor(Math.random() * 101); const l = Math.floor(Math.random() * 101); - return [h, s, l]; + return { h, s, l }; } // Usage: -getRandomHslColor(); // Returns: (h, s, l) (random) +getRandomHslColor(); // Returns: { h: 357, s: 53, l: 49 } (random) ``` diff --git a/snippets/javascript/color-manipulation/random-rgb-color.md b/snippets/javascript/color-manipulation/random-rgb-color.md index 7414b8bb..a9c90996 100644 --- a/snippets/javascript/color-manipulation/random-rgb-color.md +++ b/snippets/javascript/color-manipulation/random-rgb-color.md @@ -10,9 +10,9 @@ function getRandomRgbColor() { const r = Math.floor(Math.random() * 256); const g = Math.floor(Math.random() * 256); const b = Math.floor(Math.random() * 256); - return (r, g, b); + return { r, g, b }; } // Usage: -getRandomRgbColor(); // Returns: (r, g, b) (random) +getRandomRgbColor(); // Returns: { r: 189, g: 120, b: 201 } (random) ``` From 391e1f9ce51b4ee82ff9d89faccb90356f3ef56b Mon Sep 17 00:00:00 2001 From: JanluOfficial <95766563+JanluOfficial@users.noreply.github.com> Date: Fri, 10 Jan 2025 21:14:53 +0100 Subject: [PATCH 4/9] localStorage snippets --- .../clear-all-items-from-localstorage.md | 10 ++++++++++ .../get-all-keys-from-localstorage.md | 19 +++++++++++++++++++ .../update-item-in-localstorage.md | 19 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 snippets/javascript/local-storage/clear-all-items-from-localstorage.md create mode 100644 snippets/javascript/local-storage/get-all-keys-from-localstorage.md create mode 100644 snippets/javascript/local-storage/update-item-in-localstorage.md diff --git a/snippets/javascript/local-storage/clear-all-items-from-localstorage.md b/snippets/javascript/local-storage/clear-all-items-from-localstorage.md new file mode 100644 index 00000000..1c1b293a --- /dev/null +++ b/snippets/javascript/local-storage/clear-all-items-from-localstorage.md @@ -0,0 +1,10 @@ +--- +title: Clear all items from localStorage +description: Removes all values in localStorage, no matter what key they're under. +author: JanluOfficial +tags: localStorage,storage +--- + +```js +localStorage.clear(); +``` \ No newline at end of file diff --git a/snippets/javascript/local-storage/get-all-keys-from-localstorage.md b/snippets/javascript/local-storage/get-all-keys-from-localstorage.md new file mode 100644 index 00000000..f7789f9e --- /dev/null +++ b/snippets/javascript/local-storage/get-all-keys-from-localstorage.md @@ -0,0 +1,19 @@ +--- +title: Get all keys from localStorage +description: Gets all the keys currently assigned in localStorage. +author: JanluOfficial +tags: localStorage,storage +--- + +```js +function getAllKeysFromLocalStorage() { + const keys = []; + for (let i = 0; i < localStorage.length; i++) { + keys.push(localStorage.key(i)); + } + return keys; +} + +// Usage: +getAllKeysFromLocalStorage(); // Returns all keys from localStorage +``` \ No newline at end of file diff --git a/snippets/javascript/local-storage/update-item-in-localstorage.md b/snippets/javascript/local-storage/update-item-in-localstorage.md new file mode 100644 index 00000000..46f3ac26 --- /dev/null +++ b/snippets/javascript/local-storage/update-item-in-localstorage.md @@ -0,0 +1,19 @@ +--- +title: Update Item in localStorage +description: Updates an item with a specific key in localStorage. +author: JanluOfficial +tags: localStorage,storage +--- + +```js +function updateLocalStorageItem(key, newValue) { + if (localStorage.getItem(key) !== null) { + localStorage.setItem(key, newValue); + } else { + console.error(`Item with key "${key}" does not exist in LocalStorage.`); + } +} + +// Usage: +updateLocalStorageItem('username', 'newUsername'); +``` \ No newline at end of file From ba46e47195393930c43edc1a32f7d76a6aaf9b15 Mon Sep 17 00:00:00 2001 From: JanluOfficial <95766563+JanluOfficial@users.noreply.github.com> Date: Fri, 10 Jan 2025 22:41:13 +0100 Subject: [PATCH 5/9] DOM Manipulation Snippets --- .../add-a-css-class-to-an-element.md | 18 ++++++++++++++++++ .../get-computed-style-from-an-element.md | 19 +++++++++++++++++++ .../remove-a-css-class-from-an-element.md | 18 ++++++++++++++++++ .../toggle-a-css-class-on-an-element.md | 18 ++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 snippets/javascript/dom-manipulation/add-a-css-class-to-an-element.md create mode 100644 snippets/javascript/dom-manipulation/get-computed-style-from-an-element.md create mode 100644 snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md create mode 100644 snippets/javascript/dom-manipulation/toggle-a-css-class-on-an-element.md diff --git a/snippets/javascript/dom-manipulation/add-a-css-class-to-an-element.md b/snippets/javascript/dom-manipulation/add-a-css-class-to-an-element.md new file mode 100644 index 00000000..2d340bea --- /dev/null +++ b/snippets/javascript/dom-manipulation/add-a-css-class-to-an-element.md @@ -0,0 +1,18 @@ +--- +title: Add a CSS Class to an element +description: Add a CSS class to a HTML element. +author: JanluOfficial +tags: css,style +--- + +```js +function addClass(element, className) { + if (element && className) { + element.classList.add(className); + } +} + +// Usage: +const myElement = document.getElementById("myElement"); +addClass(myElement, "myClass"); +``` \ No newline at end of file diff --git a/snippets/javascript/dom-manipulation/get-computed-style-from-an-element.md b/snippets/javascript/dom-manipulation/get-computed-style-from-an-element.md new file mode 100644 index 00000000..ef6d3fc9 --- /dev/null +++ b/snippets/javascript/dom-manipulation/get-computed-style-from-an-element.md @@ -0,0 +1,19 @@ +--- +title: Get Computed Style from an Element +description: Retrieve the computed style of a specific CSS property from an HTML element. +author: JanluOfficial +tags: css,style +--- + +```js +function getComputedStyle(element, styleProp) { + if (element && styleProp) { + return window.getComputedStyle(element, null).getPropertyValue(styleProp); + } + return null; +} + +// Usage: +const myElement = document.getElementById("myElement"); +toggleClass(myElement, "background-color"); +``` \ No newline at end of file diff --git a/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md b/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md new file mode 100644 index 00000000..aaf11f64 --- /dev/null +++ b/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md @@ -0,0 +1,18 @@ +--- +title: Remove a CSS Class to an element +description: Remove a CSS class to a HTML element. +author: JanluOfficial +tags: css,style +--- + +```js +function removeClass(element, className) { + if (element && className) { + element.classList.remove(className); + } +} + +// Usage: +const myElement = document.getElementById("myElement"); +removeClass(myElement, "myClass"); +``` \ No newline at end of file diff --git a/snippets/javascript/dom-manipulation/toggle-a-css-class-on-an-element.md b/snippets/javascript/dom-manipulation/toggle-a-css-class-on-an-element.md new file mode 100644 index 00000000..dc6acd2a --- /dev/null +++ b/snippets/javascript/dom-manipulation/toggle-a-css-class-on-an-element.md @@ -0,0 +1,18 @@ +--- +title: Toggle a CSS Class on an Element +description: Toggle a CSS class on an HTML element. +author: JanluOfficial +tags: css,style +--- + +```js +function toggleClass(element, className) { + if (element && className) { + element.classList.toggle(className); + } +} + +// Usage: +const myElement = document.getElementById("myElement"); +toggleClass(myElement, "myClass"); +``` \ No newline at end of file From cc068ae72eeb25504b91e9d472aa4a7fe5a49e39 Mon Sep 17 00:00:00 2001 From: JanluOfficial <95766563+JanluOfficial@users.noreply.github.com> Date: Fri, 10 Jan 2025 22:58:22 +0100 Subject: [PATCH 6/9] Array Functions --- .../array-manipulation/combine-arrays.md | 18 ++++++++++++++++++ .../array-manipulation/union-arrays.md | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 snippets/javascript/array-manipulation/combine-arrays.md create mode 100644 snippets/javascript/array-manipulation/union-arrays.md diff --git a/snippets/javascript/array-manipulation/combine-arrays.md b/snippets/javascript/array-manipulation/combine-arrays.md new file mode 100644 index 00000000..736690a6 --- /dev/null +++ b/snippets/javascript/array-manipulation/combine-arrays.md @@ -0,0 +1,18 @@ +--- +title: Zip Arrays +description: Combines two arrays by pairing corresponding elements from each array. +author: JanluOfficial +tags: array,map +--- + +```js +function combineArrays(array1, array2) { + return array1.concat(array2); +} + +// Usage: +const array1 = [1, 2, 3]; +const array2 = [1, 2, 3]; +const combinedArray = combineArrays(array1, array2); +console.log(combinedArray); // Output: [1, 2, 3, 1, 2, 3] +``` \ No newline at end of file diff --git a/snippets/javascript/array-manipulation/union-arrays.md b/snippets/javascript/array-manipulation/union-arrays.md new file mode 100644 index 00000000..cc6d7573 --- /dev/null +++ b/snippets/javascript/array-manipulation/union-arrays.md @@ -0,0 +1,18 @@ +--- +title: Zip Arrays +description: Combines two arrays by pairing corresponding elements from each array. +author: JanluOfficial +tags: array,map +--- + +```js +function unionArrays(array1, array2) { + return Array.from(new Set([...array1, ...array2])); +} + +// Usage: +const array1 = [1, 2, 3]; +const array2 = [2, 3, 4]; +const unionArray = unionArrays(array1, array2); +console.log(unionArray); // Output: [1, 2, 3, 4] +``` \ No newline at end of file From 780703633b7e9fb1d69bdd84363f25f011f2d4ae Mon Sep 17 00:00:00 2001 From: JanluOfficial <95766563+JanluOfficial@users.noreply.github.com> Date: Fri, 10 Jan 2025 23:04:03 +0100 Subject: [PATCH 7/9] Combine Objects and adjustments to combine/union arrays --- .../array-manipulation/combine-arrays.md | 6 +++--- .../array-manipulation/union-arrays.md | 6 +++--- .../object-manipulation/combine-objects.md | 18 ++++++++++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 snippets/javascript/object-manipulation/combine-objects.md diff --git a/snippets/javascript/array-manipulation/combine-arrays.md b/snippets/javascript/array-manipulation/combine-arrays.md index 736690a6..a9c25e91 100644 --- a/snippets/javascript/array-manipulation/combine-arrays.md +++ b/snippets/javascript/array-manipulation/combine-arrays.md @@ -1,8 +1,8 @@ --- -title: Zip Arrays -description: Combines two arrays by pairing corresponding elements from each array. +title: Combine Arrays +description: Concatenates two arrays into one. author: JanluOfficial -tags: array,map +tags: array,concat --- ```js diff --git a/snippets/javascript/array-manipulation/union-arrays.md b/snippets/javascript/array-manipulation/union-arrays.md index cc6d7573..c11c0acf 100644 --- a/snippets/javascript/array-manipulation/union-arrays.md +++ b/snippets/javascript/array-manipulation/union-arrays.md @@ -1,8 +1,8 @@ --- -title: Zip Arrays -description: Combines two arrays by pairing corresponding elements from each array. +title: Union Arrays +description: Combines two arrays into one with unique elements. author: JanluOfficial -tags: array,map +tags: array, set --- ```js diff --git a/snippets/javascript/object-manipulation/combine-objects.md b/snippets/javascript/object-manipulation/combine-objects.md new file mode 100644 index 00000000..24275a7f --- /dev/null +++ b/snippets/javascript/object-manipulation/combine-objects.md @@ -0,0 +1,18 @@ +--- +title: Combine Objects +description: Merges two objects into one. +author: JanluOfficial +tags: object,merge +--- + +```js +function combineObjects(obj1, obj2) { + return { ...obj1, ...obj2 }; +} + +// Usage: +const obj1 = { a: 1, b: 2 }; +const obj2 = { c: 3, d: 4 }; +const combinedObject = combineObjects(obj1, obj2); +console.log(combinedObject); // Output: { a: 1, b: 2, c: 3, d: 4 } +``` \ No newline at end of file From 694b08dba96432eac874f38e95821e7e376d174f Mon Sep 17 00:00:00 2001 From: JanluOfficial <95766563+JanluOfficial@users.noreply.github.com> Date: Fri, 10 Jan 2025 23:43:30 +0100 Subject: [PATCH 8/9] Title fix, forgor to commit this :skull: --- .../dom-manipulation/remove-a-css-class-from-an-element.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md b/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md index aaf11f64..b0f05aa6 100644 --- a/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md +++ b/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md @@ -1,5 +1,5 @@ --- -title: Remove a CSS Class to an element +title: Remove a CSS Class from an element description: Remove a CSS class to a HTML element. author: JanluOfficial tags: css,style From 75ae16ecf9c50e1eb4aa1488fc1d2793a9f2cfec Mon Sep 17 00:00:00 2001 From: JanluOfficial <95766563+JanluOfficial@users.noreply.github.com> Date: Fri, 10 Jan 2025 23:45:16 +0100 Subject: [PATCH 9/9] Fix description too bruh im stoobid --- .../dom-manipulation/remove-a-css-class-from-an-element.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md b/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md index b0f05aa6..ef8ab09c 100644 --- a/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md +++ b/snippets/javascript/dom-manipulation/remove-a-css-class-from-an-element.md @@ -1,6 +1,6 @@ --- title: Remove a CSS Class from an element -description: Remove a CSS class to a HTML element. +description: Remove a CSS class from a HTML element. author: JanluOfficial tags: css,style ---