Skip to content

Commit

Permalink
Merge pull request #263 from Axorax/main
Browse files Browse the repository at this point in the history
feat: Add more JavaScript snippets
  • Loading branch information
Bashamega authored Aug 11, 2024
2 parents 832a166 + b5bc10c commit 07a380e
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 1 deletion.
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!"
```
7 changes: 7 additions & 0 deletions src/db/codesnippets/posts/javascript/getcurrentdateandtime.md
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));
```
7 changes: 7 additions & 0 deletions src/db/codesnippets/posts/javascript/howtogetprocessuptime.md
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]
```

0 comments on commit 07a380e

Please sign in to comment.