Skip to content

Commit 0ef3160

Browse files
committed
snippets: hex to rgb color
1 parent 621db73 commit 0ef3160

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

public/consolidated/c.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"numbers"
3939
],
4040
"contributors": [],
41-
"code": "#include<stdio.h>\nvoid swap(int* num1,int* num2){\n *num1 = *num1 + *num2;\n *num2 = *num1 - *num2;\n *num1 = *num1 - *num2;\n}\n\n// Usage:\nint a = 3,b = 4;\nswap(&a,&b); // simply use printf after this to print swapped values\n"
41+
"code": "#include<stdio.h>\nvoid swap(int* num1,int* num2){\n *num1 = *num1 + *num2;\n *num2 = *num1 - *num2;\n *num1 = *num1 - *num2;\n}\n\n// Usage:\nint a = 3,b = 4;\nswap(&a,&b); // swaps the values of the a and b variables\n"
4242
}
4343
]
4444
}

public/consolidated/javascript.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,17 @@
8080
{
8181
"categoryName": "Color Manipulation",
8282
"snippets": [
83+
{
84+
"title": "Hex to RGB Color",
85+
"description": "Converts hexadecimal color code to RGB color values.",
86+
"author": "pvictordev",
87+
"tags": [
88+
"color",
89+
"conversion"
90+
],
91+
"contributors": [],
92+
"code": "function hexToRgb(r, g, b) {\n return (\n \"#\" +\n [r, g, b]\n .map((x) => {\n const hex = x.toString(16);\n return hex.length === 1 ? \"0\" + hex : hex;\n })\n .join(\"\")\n );\n},\n\n// Usage:\nconsole.log(hexToRgb(\"#ff5733\")); // { r: 255, g: 87, b: 51 }\nconsole.log(hexToRgb(\"#ffff\")); // { r: 0, g: 255, b: 255 }\n"
93+
},
8394
{
8495
"title": "RGB to Hex Color",
8596
"description": "Converts RGB color values to hexadecimal color code.",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
title: Hex to RGB Color
3+
description: Converts hexadecimal color code to RGB color values.
4+
author: pvictordev
5+
tags: color,conversion
6+
---
7+
8+
```js
9+
function hexToRgb(r, g, b) {
10+
return (
11+
"#" +
12+
[r, g, b]
13+
.map((x) => {
14+
const hex = x.toString(16);
15+
return hex.length === 1 ? "0" + hex : hex;
16+
})
17+
.join("")
18+
);
19+
},
20+
21+
// Usage:
22+
console.log(hexToRgb("#ff5733")); // { r: 255, g: 87, b: 51 }
23+
console.log(hexToRgb("#ffff")); // { r: 0, g: 255, b: 255 }
24+
```

0 commit comments

Comments
 (0)