Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add more JavaScript snippets #263

Merged
merged 20 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/db/codesnippets/posts/javascript/checkforsubstring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Check for substring

```js
const text = "Hello, world!";
const substring = "world";

console.log(text.includes(substring)); // true
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Check if variable is an array

```js
const arr = [1, 2, 3];
const notArr = "hello";

console.log(Array.isArray(arr)); // true
console.log(Array.isArray(notArr)); // false
```
75 changes: 74 additions & 1 deletion src/db/codesnippets/posts/javascript/content.json
Original file line number Diff line number Diff line change
@@ -1 +1,74 @@
[]
[
{
"title": "How to get process uptime",
"author": {
"name": "Axorax",
"githubLink": "https://github.com/Axorax",
"about": "I like stuff... 🤨"
},
"doc": "howtogetprocessuptime"
},
{
"title": "Check if variable is an array",
"author": {
"name": "Axorax",
"githubLink": "https://github.com/Axorax",
"about": "I like stuff... 🤨"
},
"doc": "checkifvariableisanarray"
},
{
"title": "Get current date and time",
"author": {
"name": "Axorax",
"githubLink": "https://github.com/Axorax",
"about": "I like stuff... 🤨"
},
"doc": "getcurrentdateandtime"
},
{
"title": "Convert string to uppercase",
"author": {
"name": "Axorax",
"githubLink": "https://github.com/Axorax",
"about": "I like stuff... 🤨"
},
"doc": "convertstringtouppercase"
},
{
"title": "Merge two arrays",
"author": {
"name": "Axorax",
"githubLink": "https://github.com/Axorax",
"about": "I like stuff... 🤨"
},
"doc": "mergetwoarrays"
},
{
"title": "Check for substring",
"author": {
"name": "Axorax",
"githubLink": "https://github.com/Axorax",
"about": "I like stuff... 🤨"
},
"doc": "checkforsubstring"
},
{
"title": "Remove duplicates from an array",
"author": {
"name": "Axorax",
"githubLink": "https://github.com/Axorax",
"about": "I like stuff... 🤨"
},
"doc": "removeduplicatesfromanarray"
},
{
"title": "Get random integer from range",
"author": {
"name": "Axorax",
"githubLink": "https://github.com/Axorax",
"about": "I like stuff... 🤨"
},
"doc": "getrandomintegerfromrange"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Convert string to uppercase

```js
const str = "hello, world!";

const uppercaseStr = str.toUpperCase();

console.log(uppercaseStr); // "HELLO, WORLD!"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Get current date and time

```js
const now = new Date();

console.log(now.toLocaleString()); // "8/10/2024, 11:24:15 AM"
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Get random integer from range

```js
function randomFromRange(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}

console.log(randomFromRange(1, 10));
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# How to get process uptime

```js
const uptime = process.uptime();

console.log(uptime);
```
9 changes: 9 additions & 0 deletions src/db/codesnippets/posts/javascript/mergetwoarrays.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Merge two arrays

```js
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const mergedArray = arr1.concat(arr2);

console.log(mergedArray); // [1, 2, 3, 4, 5, 6]
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Remove duplicates from an array

```js
const numbers = [1, 2, 2, 3, 4, 4, 5];
const uniqueNumbers = [...new Set(numbers)];

console.log(uniqueNumbers); // [1, 2, 3, 4, 5]
```
Loading