-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #263 from Axorax/main
feat: Add more JavaScript snippets
- Loading branch information
Showing
9 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
9 changes: 9 additions & 0 deletions
9
src/db/codesnippets/posts/javascript/checkifvariableisanarray.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] |
9 changes: 9 additions & 0 deletions
9
src/db/codesnippets/posts/javascript/convertstringtouppercase.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
7
src/db/codesnippets/posts/javascript/getcurrentdateandtime.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
``` |
9 changes: 9 additions & 0 deletions
9
src/db/codesnippets/posts/javascript/getrandomintegerfromrange.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
7
src/db/codesnippets/posts/javascript/howtogetprocessuptime.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
``` |
8 changes: 8 additions & 0 deletions
8
src/db/codesnippets/posts/javascript/removeduplicatesfromanarray.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | ||
``` |