chunk_id stringlengths 36 36 | source stringclasses 35
values | source_url stringlengths 0 290 | upstream_license stringclasses 1
value | document_id stringlengths 36 36 | chunk_index int64 0 324k | retrieved_at stringclasses 2
values | chunker_version stringclasses 4
values | content_hash stringlengths 15 64 | content stringlengths 50 44.7k | namespace stringclasses 9
values | source_name stringclasses 35
values | raw_text stringlengths 50 44.7k | cleaned_text stringlengths 50 44.7k | tags stringclasses 49
values | collection_name stringclasses 11
values |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3a541358-3525-47a2-9a5d-252b5be37ce8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/most-frequent-array-element.md | unknown | bb5b75a5-851e-4bfe-94b8-6f5bd2aa30ee | 3 | SemanticChunker@1.0.0 | bef0ea65a11c86f80e985992f79d06ecfc0f7f0d56b31ead975053de37238d25 | [Most frequent element in an array of primitives > A more robust implementation, using `Map`]
## A more robust implementation, using `Map`
Both of the previous implementations suffer from the same issue: **the resulting value is always a string**, even if the original values were of a different type. To address this,... | unknown | unknown | [Most frequent element in an array of primitives > A more robust implementation, using `Map`]
## A more robust implementation, using `Map`
Both of the previous implementations suffer from the same issue: **the resulting value is always a string**, even if the original values were of a different type. To address this,... | [Most frequent element in an array of primitives > A more robust implementation, using `Map`]
## A more robust implementation, using `Map`
Both of the previous implementations suffer from the same issue: **the resulting value is always a string**, even if the original values were of a different type. To address this,... | code_snippets | ||
bedd2a31-56aa-4444-839d-31c9130bd5e0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/most-frequent-array-element.md | unknown | bb5b75a5-851e-4bfe-94b8-6f5bd2aa30ee | 0 | SemanticChunker@1.0.0 | fdfc83a3b09fc7d2b6fa281556fa018c15cb257e5d82387758286a1c4445532a | ---
title: Find the most frequent element in a JavaScript array
shortTitle: Most frequent array element
language: javascript
tags: [array]
cover: collab-desk-1
excerpt: Find the most frequently occurring element in a JavaScript array of primitives or objects.
listed: true
dateModified: 2024-03-23
---
Finding the **mos... | unknown | unknown | ---
title: Find the most frequent element in a JavaScript array
shortTitle: Most frequent array element
language: javascript
tags: [array]
cover: collab-desk-1
excerpt: Find the most frequently occurring element in a JavaScript array of primitives or objects.
listed: true
dateModified: 2024-03-23
---
Finding the **mos... | ---
title: Find the most frequent element in a JavaScript array
shortTitle: Most frequent array element
language: javascript
tags: [array]
cover: collab-desk-1
excerpt: Find the most frequently occurring element in a JavaScript array of primitives or objects.
listed: true
dateModified: 2024-03-23
---
Finding the **mos... | code_snippets | ||
cba58229-348d-41db-9bf0-60e74c508da6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/most-frequent-array-element.md | unknown | bb5b75a5-851e-4bfe-94b8-6f5bd2aa30ee | 1 | SemanticChunker@1.0.0 | e861dddecf46c0c1bf26c626808057296a2a62208edf4a88ac4d97e572fa78b9 | [Most frequent element in an array of primitives]
## Most frequent element in an array of primitives
Primitive values are easy to compare and count the frequency of. All you have to do is use `Array.prototype.reduce()` to create an **object** with the unique values of the array as keys and their frequencies as values... | unknown | unknown | [Most frequent element in an array of primitives]
## Most frequent element in an array of primitives
Primitive values are easy to compare and count the frequency of. All you have to do is use `Array.prototype.reduce()` to create an **object** with the unique values of the array as keys and their frequencies as values... | [Most frequent element in an array of primitives]
## Most frequent element in an array of primitives
Primitive values are easy to compare and count the frequency of. All you have to do is use `Array.prototype.reduce()` to create an **object** with the unique values of the array as keys and their frequencies as values... | code_snippets | ||
1c264e42-ef0d-4262-8807-c03e2fe6ddb0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/module-cheatsheet.md | unknown | 445747cd-0f4b-49cd-99a9-fceb26bb7bc8 | 3 | SemanticChunker@1.0.0 | ba21fd6f56814d91dfe730e4754709459bf00c284e1abad296296491517b381e | [Named exports > Default + named]
## Default + named
```js title="environment.js"
export const envType = 'DEV';
const environment = {
key: 'this-is-a-secret',
port: 8000
};
export default environment;
```
```js title="index.js"
import { envType }, environment from 'environment';
const { key, port } = environme... | unknown | unknown | [Named exports > Default + named]
## Default + named
```js title="environment.js"
export const envType = 'DEV';
const environment = {
key: 'this-is-a-secret',
port: 8000
};
export default environment;
```
```js title="index.js"
import { envType }, environment from 'environment';
const { key, port } = environme... | [Named exports > Default + named]
## Default + named
```js title="environment.js"
export const envType = 'DEV';
const environment = {
key: 'this-is-a-secret',
port: 8000
};
export default environment;
```
```js title="index.js"
import { envType }, environment from 'environment';
const { key, port } = environme... | code_snippets | ||
24595f6f-7003-48bb-933c-a14eb1b0af81 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/module-cheatsheet.md | unknown | 445747cd-0f4b-49cd-99a9-fceb26bb7bc8 | 2 | SemanticChunker@1.0.0 | 803738dc19865a6b9d0245ff1844bcd3d46cb6865f48f16c041df4f22bac312d | [Named exports > Default exports]
## Default exports
```js title="environment.js"
const environment = {
key: 'this-is-a-secret',
port: 8000
};
export default environment;
```
```js title="index.js"
import environment from 'environment';
const { key, port } = environment;
```
- Default exports expose a default ... | unknown | unknown | [Named exports > Default exports]
## Default exports
```js title="environment.js"
const environment = {
key: 'this-is-a-secret',
port: 8000
};
export default environment;
```
```js title="index.js"
import environment from 'environment';
const { key, port } = environment;
```
- Default exports expose a default ... | [Named exports > Default exports]
## Default exports
```js title="environment.js"
const environment = {
key: 'this-is-a-secret',
port: 8000
};
export default environment;
```
```js title="index.js"
import environment from 'environment';
const { key, port } = environment;
```
- Default exports expose a default ... | code_snippets | ||
314a103b-0bc5-4497-b6a4-39a0042c4b55 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/module-cheatsheet.md | unknown | 445747cd-0f4b-49cd-99a9-fceb26bb7bc8 | 0 | SemanticChunker@1.0.0 | efdf2d3c394ea8f3d9455cd6911b62e18088a3220bd5bea111fb02da177fef46 | ---
title: JavaScript modules Cheat Sheet
language: javascript
tags: [cheatsheet]
cover: mountain-lake-2
excerpt: Learn everything you need to know about JavaScript modules with this handy cheatsheet.
listed: true
dateModified: 2021-06-12
--- | unknown | unknown | ---
title: JavaScript modules Cheat Sheet
language: javascript
tags: [cheatsheet]
cover: mountain-lake-2
excerpt: Learn everything you need to know about JavaScript modules with this handy cheatsheet.
listed: true
dateModified: 2021-06-12
--- | ---
title: JavaScript modules Cheat Sheet
language: javascript
tags: [cheatsheet]
cover: mountain-lake-2
excerpt: Learn everything you need to know about JavaScript modules with this handy cheatsheet.
listed: true
dateModified: 2021-06-12
--- | code_snippets | ||
33ccb9bb-aada-4833-9daa-df9dc71899c8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/module-cheatsheet.md | unknown | 445747cd-0f4b-49cd-99a9-fceb26bb7bc8 | 1 | SemanticChunker@1.0.0 | 5b74e09e0f4a92d2ccf049ec85a40471c5592384b21cc7176eaf1ce34779923f | [Named exports]
## Named exports
```js title="environment.js"
export const key = 'this-is-a-secret';
```
```js title="index.js"
import { key } from 'environment';
```
- Named exports use a name.
- A module can have any number of named exports.
- Import and export name should be the same.
- Importing requires `{}`. | unknown | unknown | [Named exports]
## Named exports
```js title="environment.js"
export const key = 'this-is-a-secret';
```
```js title="index.js"
import { key } from 'environment';
```
- Named exports use a name.
- A module can have any number of named exports.
- Import and export name should be the same.
- Importing requires `{}`. | [Named exports]
## Named exports
```js title="environment.js"
export const key = 'this-is-a-secret';
```
```js title="index.js"
import { key } from 'environment';
```
- Named exports use a name.
- A module can have any number of named exports.
- Import and export name should be the same.
- Importing requires `{}`. | code_snippets | ||
90e72156-7308-4fb9-bf41-cad8d4b1ccdf | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/module-cheatsheet.md | unknown | 445747cd-0f4b-49cd-99a9-fceb26bb7bc8 | 7 | SemanticChunker@1.0.0 | 99a6b341ffe12e954a92c0d71583036efd9002832cdb1ae51c95d8f18a980f3d | [Named exports > Import all]
## Import all
```js title="environment.js"
export const envType = 'DEV';
const environment = {
key: 'this-is-a-secret',
port: 8000
};
export default environment;
```
```js title="index.js"
import * as env from 'environment';
const { default: { key, port}, envType } = environment;
`... | unknown | unknown | [Named exports > Import all]
## Import all
```js title="environment.js"
export const envType = 'DEV';
const environment = {
key: 'this-is-a-secret',
port: 8000
};
export default environment;
```
```js title="index.js"
import * as env from 'environment';
const { default: { key, port}, envType } = environment;
`... | [Named exports > Import all]
## Import all
```js title="environment.js"
export const envType = 'DEV';
const environment = {
key: 'this-is-a-secret',
port: 8000
};
export default environment;
```
```js title="index.js"
import * as env from 'environment';
const { default: { key, port}, envType } = environment;
`... | code_snippets | ||
97eea8cd-41ef-42cb-91d7-8aa5af499f3e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/module-cheatsheet.md | unknown | 445747cd-0f4b-49cd-99a9-fceb26bb7bc8 | 6 | SemanticChunker@1.0.0 | ecb14ff954815910cb973e561238986118a98cd3549b28cd1df86d6287c233db | [Named exports > Rename import]
## Rename import
```js title="environment.js"
export const key = 'this-is-a-secret';
```
```js title="index.js"
import { key as authKey } from 'environment';
```
- Named imports can make use of the `as` keyword to rename an import.
- Import name (before the `as` keyword) should be t... | unknown | unknown | [Named exports > Rename import]
## Rename import
```js title="environment.js"
export const key = 'this-is-a-secret';
```
```js title="index.js"
import { key as authKey } from 'environment';
```
- Named imports can make use of the `as` keyword to rename an import.
- Import name (before the `as` keyword) should be t... | [Named exports > Rename import]
## Rename import
```js title="environment.js"
export const key = 'this-is-a-secret';
```
```js title="index.js"
import { key as authKey } from 'environment';
```
- Named imports can make use of the `as` keyword to rename an import.
- Import name (before the `as` keyword) should be t... | code_snippets | ||
98772407-189c-4980-9140-f4f0194f786a | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/module-cheatsheet.md | unknown | 445747cd-0f4b-49cd-99a9-fceb26bb7bc8 | 4 | SemanticChunker@1.0.0 | 90ba161faa995a1816b42f07e991a5c5c2b1975d6b4964c1099f77d9277351d3 | [Named exports > Export list]
## Export list
```js title="environment.js"
const key = 'this-is-a-secret';
const port = 8000;
export {
key,
port
};
```
```js title="index.js"
import { key, port } from 'environment';
```
- An export list is a compact way to write multiple named exports.
- Rules about number of ex... | unknown | unknown | [Named exports > Export list]
## Export list
```js title="environment.js"
const key = 'this-is-a-secret';
const port = 8000;
export {
key,
port
};
```
```js title="index.js"
import { key, port } from 'environment';
```
- An export list is a compact way to write multiple named exports.
- Rules about number of ex... | [Named exports > Export list]
## Export list
```js title="environment.js"
const key = 'this-is-a-secret';
const port = 8000;
export {
key,
port
};
```
```js title="index.js"
import { key, port } from 'environment';
```
- An export list is a compact way to write multiple named exports.
- Rules about number of ex... | code_snippets | ||
b1d7565d-e055-4cb8-b71d-1048fa38fbc9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/module-cheatsheet.md | unknown | 445747cd-0f4b-49cd-99a9-fceb26bb7bc8 | 5 | SemanticChunker@1.0.0 | 0480bc6b777e96cca4681a50688ec8c64f71a68ca40b2bf6ee1639ef542b1ee9 | [Named exports > Rename export]
## Rename export
```js title="environment.js"
const key = 'this-is-a-secret';
export { key as authKey };
```
```js title="index.js"
import { authKey } from 'environment';
```
- Named exports can make use of the `as` keyword to rename an export.
- Import name should be the same as t... | unknown | unknown | [Named exports > Rename export]
## Rename export
```js title="environment.js"
const key = 'this-is-a-secret';
export { key as authKey };
```
```js title="index.js"
import { authKey } from 'environment';
```
- Named exports can make use of the `as` keyword to rename an export.
- Import name should be the same as t... | [Named exports > Rename export]
## Rename export
```js title="environment.js"
const key = 'this-is-a-secret';
export { key as authKey };
```
```js title="index.js"
import { authKey } from 'environment';
```
- Named exports can make use of the `as` keyword to rename an export.
- Import name should be the same as t... | code_snippets | ||
2e0cdaf3-28b0-463c-9f05-ffdf50354851 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/n-gram-fuzzy-matching.md | unknown | 89a9a6a8-35f5-484d-bfe6-6064869b2bbe | 8 | SemanticChunker@1.0.0 | 15c169db600ffec79685bb62bad73f180c8389dd7ccd5bf3e8e8e1748046a408 | [Fuzzy search > Updating the search function]
Pretty cool, right? We can now account for typos and misspellings, and the results are still relevant. The `fuzziness` parameter might need some tweaking to be perfect for your use case, but overall, it seems to work well. | unknown | unknown | [Fuzzy search > Updating the search function]
Pretty cool, right? We can now account for typos and misspellings, and the results are still relevant. The `fuzziness` parameter might need some tweaking to be perfect for your use case, but overall, it seems to work well. | [Fuzzy search > Updating the search function]
Pretty cool, right? We can now account for typos and misspellings, and the results are still relevant. The `fuzziness` parameter might need some tweaking to be perfect for your use case, but overall, it seems to work well. | code_snippets | ||
3f32a45c-fefe-4e58-abc9-6d4e8b461de9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/n-gram-fuzzy-matching.md | unknown | 89a9a6a8-35f5-484d-bfe6-6064869b2bbe | 3 | SemanticChunker@1.0.0 | 411d4ab69f8566baed038cfce648531fe20bc17d0d74eee7d7657ac6dfda0b34 | [Fuzzy matching > N-gram indexing]
## N-gram indexing
Same as before, we'll employ an **inverted index** to store these values. After all, we want to be able to search for them same as regular terms and speed is paramount. Given the fact that we now need to store both terms and n-grams, we'll make some changes to our... | unknown | unknown | [Fuzzy matching > N-gram indexing]
## N-gram indexing
Same as before, we'll employ an **inverted index** to store these values. After all, we want to be able to search for them same as regular terms and speed is paramount. Given the fact that we now need to store both terms and n-grams, we'll make some changes to our... | [Fuzzy matching > N-gram indexing]
## N-gram indexing
Same as before, we'll employ an **inverted index** to store these values. After all, we want to be able to search for them same as regular terms and speed is paramount. Given the fact that we now need to store both terms and n-grams, we'll make some changes to our... | code_snippets | ||
409c810e-0848-44ff-82d0-56f4113353e2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/n-gram-fuzzy-matching.md | unknown | 89a9a6a8-35f5-484d-bfe6-6064869b2bbe | 1 | SemanticChunker@1.0.0 | 35a93b2c931ea16c6be5209ec6dd41363198f9c2601c2083da529b72a0bfc600 | [Fuzzy matching]
## Fuzzy matching
Fuzzy matching is a technique that allows you to search for documents that contain a **substring of the search term**, even if the substring is not an exact match. This is particularly useful when users make **typos or misspellings**, which is quite common in the real world. | unknown | unknown | [Fuzzy matching]
## Fuzzy matching
Fuzzy matching is a technique that allows you to search for documents that contain a **substring of the search term**, even if the substring is not an exact match. This is particularly useful when users make **typos or misspellings**, which is quite common in the real world. | [Fuzzy matching]
## Fuzzy matching
Fuzzy matching is a technique that allows you to search for documents that contain a **substring of the search term**, even if the substring is not an exact match. This is particularly useful when users make **typos or misspellings**, which is quite common in the real world. | code_snippets | ||
45eee19f-f1dc-40cd-b054-1d4bcf4505d5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/n-gram-fuzzy-matching.md | unknown | 89a9a6a8-35f5-484d-bfe6-6064869b2bbe | 6 | SemanticChunker@1.0.0 | 5dfde74c8ae3fdf55b0073d195928b358bb26d0acb7becd0bd94aad1b7c6e6e2 | [Fuzzy search > Updating the search function]
### Updating the search function
Now that we have everything in place, we can update the search function to use the new n-gram index and scoring system. After calculating the score like before, we'll perform a **second pass** to calculate the n-gram similarity. This will ... | unknown | unknown | [Fuzzy search > Updating the search function]
### Updating the search function
Now that we have everything in place, we can update the search function to use the new n-gram index and scoring system. After calculating the score like before, we'll perform a **second pass** to calculate the n-gram similarity. This will ... | [Fuzzy search > Updating the search function]
### Updating the search function
Now that we have everything in place, we can update the search function to use the new n-gram index and scoring system. After calculating the score like before, we'll perform a **second pass** to calculate the n-gram similarity. This will ... | code_snippets | ||
5ee78c52-3834-4dbd-ab73-cb095600f22d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/n-gram-fuzzy-matching.md | unknown | 89a9a6a8-35f5-484d-bfe6-6064869b2bbe | 0 | SemanticChunker@1.0.0 | 31618deac00a999225af07c6fc60907afc9969c2aef7a7d4938574e275ea5edc | ---
title: Implementing fuzzy matching in JavaScript
shortTitle: Fuzzy search matching
language: javascript
tags: [algorithm,string]
cover: raccoon
excerpt: Having built a search engine with TF-IDF and inverted indexes, we will now implement fuzzy matching to make searching error-tolerant.
listed: true
dateModified: 20... | unknown | unknown | ---
title: Implementing fuzzy matching in JavaScript
shortTitle: Fuzzy search matching
language: javascript
tags: [algorithm,string]
cover: raccoon
excerpt: Having built a search engine with TF-IDF and inverted indexes, we will now implement fuzzy matching to make searching error-tolerant.
listed: true
dateModified: 20... | ---
title: Implementing fuzzy matching in JavaScript
shortTitle: Fuzzy search matching
language: javascript
tags: [algorithm,string]
cover: raccoon
excerpt: Having built a search engine with TF-IDF and inverted indexes, we will now implement fuzzy matching to make searching error-tolerant.
listed: true
dateModified: 20... | code_snippets | ||
6256a57a-b215-4f20-a171-97d733b77e77 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/n-gram-fuzzy-matching.md | unknown | 89a9a6a8-35f5-484d-bfe6-6064869b2bbe | 7 | SemanticChunker@1.0.0 | 9172cfbd9483a8d2ce349e992e5980eb5a4f61d05f9194b3d41afdd959f7056a | [Fuzzy search > Updating the search function]
const { termFrequency, totalTermFrequency } = matches.reduce(
(acc, match) => {
const term = match.toLowerCase();
const indexEntries = invertedIndex.get(term);
if (indexEntries) {
acc.termFrequency += indexEntries.get(docId) ?? 0;
acc.totalTermFrequency += indexEntri... | unknown | unknown | [Fuzzy search > Updating the search function]
const { termFrequency, totalTermFrequency } = matches.reduce(
(acc, match) => {
const term = match.toLowerCase();
const indexEntries = invertedIndex.get(term);
if (indexEntries) {
acc.termFrequency += indexEntries.get(docId) ?? 0;
acc.totalTermFrequency += indexEntri... | [Fuzzy search > Updating the search function]
const { termFrequency, totalTermFrequency } = matches.reduce(
(acc, match) => {
const term = match.toLowerCase();
const indexEntries = invertedIndex.get(term);
if (indexEntries) {
acc.termFrequency += indexEntries.get(docId) ?? 0;
acc.totalTermFrequency += indexEntri... | code_snippets | ||
6555930e-e00f-4dc6-9ac3-0d6ddc594670 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/n-gram-fuzzy-matching.md | unknown | 89a9a6a8-35f5-484d-bfe6-6064869b2bbe | 2 | SemanticChunker@1.0.0 | 4e4953211e65b566b948c8927b179527a8e14b2f4e32d5346fc6dae1d98add30 | [Fuzzy matching > N-grams]
### N-grams
Fuzzy matching can be implemented using various algorithms, but one of the most common approaches is to use **n-grams**. This algorithm works by breaking down a word into **smaller substrings of a fixed length**, called n-grams. The most common type of n-gram is the **trigram**,... | unknown | unknown | [Fuzzy matching > N-grams]
### N-grams
Fuzzy matching can be implemented using various algorithms, but one of the most common approaches is to use **n-grams**. This algorithm works by breaking down a word into **smaller substrings of a fixed length**, called n-grams. The most common type of n-gram is the **trigram**,... | [Fuzzy matching > N-grams]
### N-grams
Fuzzy matching can be implemented using various algorithms, but one of the most common approaches is to use **n-grams**. This algorithm works by breaking down a word into **smaller substrings of a fixed length**, called n-grams. The most common type of n-gram is the **trigram**,... | code_snippets | ||
b3134694-c325-406f-a13c-ab2cbc40d88d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/n-gram-fuzzy-matching.md | unknown | 89a9a6a8-35f5-484d-bfe6-6064869b2bbe | 5 | SemanticChunker@1.0.0 | b5cb5377d507f121d683011b3c8385b47c39c8dece1e5944dad56b5590d044f5 | [Fuzzy search > Scoring fuzzy matches]
### Scoring fuzzy matches
One method is to use a **weighing parameter** - let's call it `fuzzinness` - to control the balance between the two scores. The higher the value, the more weight is placed on n-gram matches, and the lower the value, the more weight is placed on exact ma... | unknown | unknown | [Fuzzy search > Scoring fuzzy matches]
### Scoring fuzzy matches
One method is to use a **weighing parameter** - let's call it `fuzzinness` - to control the balance between the two scores. The higher the value, the more weight is placed on n-gram matches, and the lower the value, the more weight is placed on exact ma... | [Fuzzy search > Scoring fuzzy matches]
### Scoring fuzzy matches
One method is to use a **weighing parameter** - let's call it `fuzzinness` - to control the balance between the two scores. The higher the value, the more weight is placed on n-gram matches, and the lower the value, the more weight is placed on exact ma... | code_snippets | ||
e16d7287-2f8b-49c1-8734-3c1e13b162d1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/n-gram-fuzzy-matching.md | unknown | 89a9a6a8-35f5-484d-bfe6-6064869b2bbe | 4 | SemanticChunker@1.0.0 | d5c87ba9cf99e2f48cb38b7608f69e38aed215ab1c5b2b64d3af8a15472ba65d | [Fuzzy matching > Fuzzy search]
## Fuzzy search
Having set up the indexing, we can now implement the fuzzy search. Same as before, we'll rely on the inverted index to match results. We will, however, need to **score both based on the TF-IDF score and n-gram similarity**. _How should we go about it?_ | unknown | unknown | [Fuzzy matching > Fuzzy search]
## Fuzzy search
Having set up the indexing, we can now implement the fuzzy search. Same as before, we'll rely on the inverted index to match results. We will, however, need to **score both based on the TF-IDF score and n-gram similarity**. _How should we go about it?_ | [Fuzzy matching > Fuzzy search]
## Fuzzy search
Having set up the indexing, we can now implement the fuzzy search. Same as before, we'll rely on the inverted index to match results. We will, however, need to **score both based on the TF-IDF score and n-gram similarity**. _How should we go about it?_ | code_snippets | ||
e5ddb9c2-66c9-43a8-9096-5c2f0a8fb527 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/n-gram-fuzzy-matching.md | unknown | 89a9a6a8-35f5-484d-bfe6-6064869b2bbe | 9 | SemanticChunker@1.0.0 | 22fd16fe44966e4e11d94217f8b78ed378a8e3fc5ca92b2e2a515e55b005da2f | [Fuzzy matching > Conclusion]
## Conclusion
In this article, we built on top of previous work to leverage our document index, inverted indexes, partial matching, TF-IDF and, finally, n-grams for fuzzy matching. I'd say this little search engine is pretty capable right now, enough to maybe even try out in production. ... | unknown | unknown | [Fuzzy matching > Conclusion]
## Conclusion
In this article, we built on top of previous work to leverage our document index, inverted indexes, partial matching, TF-IDF and, finally, n-grams for fuzzy matching. I'd say this little search engine is pretty capable right now, enough to maybe even try out in production. ... | [Fuzzy matching > Conclusion]
## Conclusion
In this article, we built on top of previous work to leverage our document index, inverted indexes, partial matching, TF-IDF and, finally, n-grams for fuzzy matching. I'd say this little search engine is pretty capable right now, enough to maybe even try out in production. ... | code_snippets | ||
b0f5ad69-f3e7-41a1-a489-8518790686cf | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nest-objects.md | unknown | fc771f04-9729-42ae-8d95-9fac2a05276b | 0 | SemanticChunker@1.0.0 | 3d07ccce61e448cb7a7a6feb24dc599574e08c325163bf10ec865bed62ed93ca | ---
title: Nest linked JavaScript objects
shortTitle: Nest objects
language: javascript
tags: [object,recursion]
cover: birds
excerpt: Learn how to recursively nest objects linked to one another in a flat array.
listed: true
dateModified: 2024-06-06
---
More than once in my coding career, I've come across impractical ... | unknown | unknown | ---
title: Nest linked JavaScript objects
shortTitle: Nest objects
language: javascript
tags: [object,recursion]
cover: birds
excerpt: Learn how to recursively nest objects linked to one another in a flat array.
listed: true
dateModified: 2024-06-06
---
More than once in my coding career, I've come across impractical ... | ---
title: Nest linked JavaScript objects
shortTitle: Nest objects
language: javascript
tags: [object,recursion]
cover: birds
excerpt: Learn how to recursively nest objects linked to one another in a flat array.
listed: true
dateModified: 2024-06-06
---
More than once in my coding career, I've come across impractical ... | code_snippets | ||
ddd0dc64-0557-4bc4-b400-3f824f7c84a4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nest-objects.md | unknown | fc771f04-9729-42ae-8d95-9fac2a05276b | 1 | SemanticChunker@1.0.0 | 1f7f127a2d6bc69f4a4dbfe6e22e0c574c36a7ca4ff568b2ed12fddfbbccfa04 | ```js
const nest = (items, id = null, link = 'parentId') =>
items
.filter(item => item[link] === id)
.map(item => ({ ...item, children: nest(items, item.id, link) }));
const comments = [
{ id: 1, parentId: null },
{ id: 2, parentId: 1 },
{ id: 3, parentId: 1 },
{ id: 4, parentId: 2 },
{ id: 5, parentId: 4 }
];... | unknown | unknown | ```js
const nest = (items, id = null, link = 'parentId') =>
items
.filter(item => item[link] === id)
.map(item => ({ ...item, children: nest(items, item.id, link) }));
const comments = [
{ id: 1, parentId: null },
{ id: 2, parentId: 1 },
{ id: 3, parentId: 1 },
{ id: 4, parentId: 2 },
{ id: 5, parentId: 4 }
];... | ```js
const nest = (items, id = null, link = 'parentId') =>
items
.filter(item => item[link] === id)
.map(item => ({ ...item, children: nest(items, item.id, link) }));
const comments = [
{ id: 1, parentId: null },
{ id: 2, parentId: 1 },
{ id: 3, parentId: 1 },
{ id: 4, parentId: 2 },
{ id: 5, parentId: 4 }
];... | code_snippets | ||
969107c9-22d8-41d3-90f2-e6064179640c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nth-number-root.md | unknown | 5b41e1ec-6786-48e8-888a-6c42c958d356 | 0 | SemanticChunker@1.0.0 | 50d2dfe1c1c18087f755c3c7031a2feabeedc62f86e6b7729950554f47d0f549 | ---
title: Calculate the nth root of a number in JavaScript
shortTitle: Nth root of number
language: javascript
tags: [math]
cover: tree-roots
excerpt: Use `Math.pow()` to calculate the nth root of a given number in JavaScript.
listed: true
dateModified: 2024-02-17
---
The **nth root** of a number `x` is a value that,... | unknown | unknown | ---
title: Calculate the nth root of a number in JavaScript
shortTitle: Nth root of number
language: javascript
tags: [math]
cover: tree-roots
excerpt: Use `Math.pow()` to calculate the nth root of a given number in JavaScript.
listed: true
dateModified: 2024-02-17
---
The **nth root** of a number `x` is a value that,... | ---
title: Calculate the nth root of a number in JavaScript
shortTitle: Nth root of number
language: javascript
tags: [math]
cover: tree-roots
excerpt: Use `Math.pow()` to calculate the nth root of a given number in JavaScript.
listed: true
dateModified: 2024-02-17
---
The **nth root** of a number `x` is a value that,... | code_snippets | ||
3e107289-f34e-43e1-a251-55ee7b331a68 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nullish-coalescing-optional-chaining.md | unknown | 42372443-be7e-41b4-a3b6-ff8324f248be | 2 | SemanticChunker@1.0.0 | 443e42b6e245497c9838c0989c472fec88e6ca0c255652bfd98aeb6e5d19f91f | [Optional chaining > Nullish coalescing]
## Nullish coalescing
<baseline-support featureId="nullish-coalescing">
</baseline-support>
In the same spirit, the [nullish coalescing operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator) (`??`) is a **logical ope... | unknown | unknown | [Optional chaining > Nullish coalescing]
## Nullish coalescing
<baseline-support featureId="nullish-coalescing">
</baseline-support>
In the same spirit, the [nullish coalescing operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator) (`??`) is a **logical ope... | [Optional chaining > Nullish coalescing]
## Nullish coalescing
<baseline-support featureId="nullish-coalescing">
</baseline-support>
In the same spirit, the [nullish coalescing operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_operator) (`??`) is a **logical ope... | code_snippets | ||
64f01362-f0a4-4fc7-9017-06896a78d618 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nullish-coalescing-optional-chaining.md | unknown | 42372443-be7e-41b4-a3b6-ff8324f248be | 0 | SemanticChunker@1.0.0 | 4f039fa6ac751143faf935b650d07caba2c0e3744ad603ac366ec8e895346039 | ---
title: How can I use optional chaining and nullish coalescing in my JavaScript project?
shortTitle: Optional chaining and nullish coalescing
language: javascript
tags: [type]
cover: purple-leaves
excerpt: JavaScript ES2020 introduced optional chaining and nullish coalescing. Learn everything you need to know with t... | unknown | unknown | ---
title: How can I use optional chaining and nullish coalescing in my JavaScript project?
shortTitle: Optional chaining and nullish coalescing
language: javascript
tags: [type]
cover: purple-leaves
excerpt: JavaScript ES2020 introduced optional chaining and nullish coalescing. Learn everything you need to know with t... | ---
title: How can I use optional chaining and nullish coalescing in my JavaScript project?
shortTitle: Optional chaining and nullish coalescing
language: javascript
tags: [type]
cover: purple-leaves
excerpt: JavaScript ES2020 introduced optional chaining and nullish coalescing. Learn everything you need to know with t... | code_snippets | ||
96b0c0c4-167b-4f86-b1a6-512e2651f16d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nullish-coalescing-optional-chaining.md | unknown | 42372443-be7e-41b4-a3b6-ff8324f248be | 3 | SemanticChunker@1.0.0 | ca165292365b0af8c684e80a229b0c84af050acd4958b3b7062101da29f07200 | [Nullish coalescing > Nullish coalescing assignment]
### Nullish coalescing assignment
The [nullish coalescing assignment operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_assignment) (`??=`) is a **logical assignment operator** that allows us to assign a value t... | unknown | unknown | [Nullish coalescing > Nullish coalescing assignment]
### Nullish coalescing assignment
The [nullish coalescing assignment operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_assignment) (`??=`) is a **logical assignment operator** that allows us to assign a value t... | [Nullish coalescing > Nullish coalescing assignment]
### Nullish coalescing assignment
The [nullish coalescing assignment operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing_assignment) (`??=`) is a **logical assignment operator** that allows us to assign a value t... | code_snippets | ||
faf0c3a2-e1fd-4340-a66e-1fd7a289f0b2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nullish-coalescing-optional-chaining.md | unknown | 42372443-be7e-41b4-a3b6-ff8324f248be | 1 | SemanticChunker@1.0.0 | 5fa1a62ebf77a5a13a4d34cd3d8b977357b76fccd3dffae1a3d5684d019eb980 | [Optional chaining]
## Optional chaining
The [optional chaining operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) (`?.`) allows us to **access deeply nested object properties** without having to validate each reference in the nesting chain. In case of a reference... | unknown | unknown | [Optional chaining]
## Optional chaining
The [optional chaining operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) (`?.`) allows us to **access deeply nested object properties** without having to validate each reference in the nesting chain. In case of a reference... | [Optional chaining]
## Optional chaining
The [optional chaining operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining) (`?.`) allows us to **access deeply nested object properties** without having to validate each reference in the nesting chain. In case of a reference... | code_snippets | ||
57fa8114-7adb-4c89-a178-9bbe05e6d741 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-validation.md | unknown | a41aa891-3417-414a-9328-f70da6092d02 | 0 | SemanticChunker@1.0.0 | 2f4fbf9ca027ec32015e3d6663416b25621681ef309f6206adc8f0d3459d3806 | ---
title: Validate a number in JavaScript
shortTitle: Validate number
language: javascript
tags: [math]
cover: flower-portrait-9
excerpt: Check if a value can be safely converted to a number in JavaScript.
listed: true
dateModified: 2024-05-17
---
Number validation is probably one of the hardest things to do even for... | unknown | unknown | ---
title: Validate a number in JavaScript
shortTitle: Validate number
language: javascript
tags: [math]
cover: flower-portrait-9
excerpt: Check if a value can be safely converted to a number in JavaScript.
listed: true
dateModified: 2024-05-17
---
Number validation is probably one of the hardest things to do even for... | ---
title: Validate a number in JavaScript
shortTitle: Validate number
language: javascript
tags: [math]
cover: flower-portrait-9
excerpt: Check if a value can be safely converted to a number in JavaScript.
listed: true
dateModified: 2024-05-17
---
Number validation is probably one of the hardest things to do even for... | code_snippets | ||
c2192daa-5fe7-431a-9c7d-0b17913e82b7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-in-range.md | unknown | 8ab23c8b-a451-4ac7-b6e3-9ceec102cd39 | 0 | SemanticChunker@1.0.0 | 11be6b80c59b7fba46fc0dece648a3c0b524e2f7e73733de94260d85bae2564a | ---
title: Check if a number is inside a given range with JavaScript
shortTitle: Number in range
language: javascript
tags: [math]
cover: white-tablet
excerpt: Check if the given number falls within the specified numeric range.
listed: true
dateModified: 2024-08-12
---
Given a number and a range, you can **check if th... | unknown | unknown | ---
title: Check if a number is inside a given range with JavaScript
shortTitle: Number in range
language: javascript
tags: [math]
cover: white-tablet
excerpt: Check if the given number falls within the specified numeric range.
listed: true
dateModified: 2024-08-12
---
Given a number and a range, you can **check if th... | ---
title: Check if a number is inside a given range with JavaScript
shortTitle: Number in range
language: javascript
tags: [math]
cover: white-tablet
excerpt: Check if the given number falls within the specified numeric range.
listed: true
dateModified: 2024-08-12
---
Given a number and a range, you can **check if th... | code_snippets | ||
369a91e4-9330-40fb-80d1-f821952476eb | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nth-array-element.md | unknown | e174d9eb-44bd-40eb-95bc-e53ca6262425 | 0 | SemanticChunker@1.0.0 | 7e322da66017422b934f1a587f09d6cb8fecc14a6e033a5e98a57c488050872c | ---
title: Get the nth element of a JavaScript array
shortTitle: Nth array element
language: javascript
tags: [array]
cover: dark-leaves-6
excerpt: Find the nth or every nth element of a JavaScript array.
listed: true
dateModified: 2024-01-19
---
Retrieving an element from a JavaScript array is most often done using i... | unknown | unknown | ---
title: Get the nth element of a JavaScript array
shortTitle: Nth array element
language: javascript
tags: [array]
cover: dark-leaves-6
excerpt: Find the nth or every nth element of a JavaScript array.
listed: true
dateModified: 2024-01-19
---
Retrieving an element from a JavaScript array is most often done using i... | ---
title: Get the nth element of a JavaScript array
shortTitle: Nth array element
language: javascript
tags: [array]
cover: dark-leaves-6
excerpt: Find the nth or every nth element of a JavaScript array.
listed: true
dateModified: 2024-01-19
---
Retrieving an element from a JavaScript array is most often done using i... | code_snippets | ||
7070d43a-c0e3-44f6-b187-d96fb62b4d64 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nth-array-element.md | unknown | e174d9eb-44bd-40eb-95bc-e53ca6262425 | 1 | SemanticChunker@1.0.0 | aac3a7216373007558b16cb8af8c7da1e4a0f4f89a3e99a4985ecaec47e1022a | [Get the nth element of a JavaScript array]
## Get the nth element of a JavaScript array
Getting the nth element of a JavaScript array can be easily done, using `Array.prototype.slice()`. The only thing you need to keep in mind is **negative indexes**, which you can be used to get the last nth element of the array.
... | unknown | unknown | [Get the nth element of a JavaScript array]
## Get the nth element of a JavaScript array
Getting the nth element of a JavaScript array can be easily done, using `Array.prototype.slice()`. The only thing you need to keep in mind is **negative indexes**, which you can be used to get the last nth element of the array.
... | [Get the nth element of a JavaScript array]
## Get the nth element of a JavaScript array
Getting the nth element of a JavaScript array can be easily done, using `Array.prototype.slice()`. The only thing you need to keep in mind is **negative indexes**, which you can be used to get the last nth element of the array.
... | code_snippets | ||
74ec3625-ccd7-4beb-9af8-1df471ff5628 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nth-array-element.md | unknown | e174d9eb-44bd-40eb-95bc-e53ca6262425 | 2 | SemanticChunker@1.0.0 | e536f6500fa86083f8a7cf333f9dee9fd6aea93cae9f0cabdc88a82fa89e137e | [Get the nth element of a JavaScript array > Get every nth element of a JavaScript array]
## Get every nth element of a JavaScript array
If you need to get every nth element of a JavaScript array, you can use `Array.prototype.filter()`. Combined with the modulo operator (`%`), you can use it to keep only the elements... | unknown | unknown | [Get the nth element of a JavaScript array > Get every nth element of a JavaScript array]
## Get every nth element of a JavaScript array
If you need to get every nth element of a JavaScript array, you can use `Array.prototype.filter()`. Combined with the modulo operator (`%`), you can use it to keep only the elements... | [Get the nth element of a JavaScript array > Get every nth element of a JavaScript array]
## Get every nth element of a JavaScript array
If you need to get every nth element of a JavaScript array, you can use `Array.prototype.filter()`. Combined with the modulo operator (`%`), you can use it to keep only the elements... | code_snippets | ||
1c26668b-71fd-4934-885e-b5779f519051 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/numeric-array-math-operations.md | unknown | 27e7b0ad-af18-4ef8-9b74-7a85bf2253b4 | 4 | SemanticChunker@1.0.0 | 9df70600fe62720d77299f17efc71e82838928d162e0d17f30467046963faeeb | [Sum of an array > Median of an array]
## Median of an array
The median of an array is the **middle number when the array is sorted**. If the array has an **odd number of elements**, the median is the middle number. If the array has an **even number of elements**, the median is the average of the two middle numbers.
... | unknown | unknown | [Sum of an array > Median of an array]
## Median of an array
The median of an array is the **middle number when the array is sorted**. If the array has an **odd number of elements**, the median is the middle number. If the array has an **even number of elements**, the median is the average of the two middle numbers.
... | [Sum of an array > Median of an array]
## Median of an array
The median of an array is the **middle number when the array is sorted**. If the array has an **odd number of elements**, the median is the middle number. If the array has an **even number of elements**, the median is the average of the two middle numbers.
... | code_snippets | ||
483c29aa-2381-42e7-8d03-eaf43ffee693 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/numeric-array-math-operations.md | unknown | 27e7b0ad-af18-4ef8-9b74-7a85bf2253b4 | 1 | SemanticChunker@1.0.0 | 4a9a5b45656534289fcabdf35fbfc0086b16b48416fce8865571205bc1640cb8 | [Sum of an array]
## Sum of an array
The sum of an array is the result of **adding all the numbers in the array together**.
Using `Array.prototype.reduce()`, you can easily calculate the sum of an array of numbers, by adding each value to an accumulator, initialized with a value of `0`.
```js
const sum = (...arr) =... | unknown | unknown | [Sum of an array]
## Sum of an array
The sum of an array is the result of **adding all the numbers in the array together**.
Using `Array.prototype.reduce()`, you can easily calculate the sum of an array of numbers, by adding each value to an accumulator, initialized with a value of `0`.
```js
const sum = (...arr) =... | [Sum of an array]
## Sum of an array
The sum of an array is the result of **adding all the numbers in the array together**.
Using `Array.prototype.reduce()`, you can easily calculate the sum of an array of numbers, by adding each value to an accumulator, initialized with a value of `0`.
```js
const sum = (...arr) =... | code_snippets | ||
97341ff6-8bf0-4827-8886-a6336b1b26fd | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/numeric-array-math-operations.md | unknown | 27e7b0ad-af18-4ef8-9b74-7a85bf2253b4 | 0 | SemanticChunker@1.0.0 | 25b6a42b2cf1c9a23451d732a5de30724ea06816a34e9724de5cb0835a1f7867 | ---
title: Perform math operations on arrays of numbers in JavaScript
shortTitle: Math operations on numeric arrays
language: javascript
tags: [array,math]
cover: red-lake
excerpt: Learn how to work with arrays of numbers in JavaScript, performing common math operations such as sum, average, product and more.
listed: t... | unknown | unknown | ---
title: Perform math operations on arrays of numbers in JavaScript
shortTitle: Math operations on numeric arrays
language: javascript
tags: [array,math]
cover: red-lake
excerpt: Learn how to work with arrays of numbers in JavaScript, performing common math operations such as sum, average, product and more.
listed: t... | ---
title: Perform math operations on arrays of numbers in JavaScript
shortTitle: Math operations on numeric arrays
language: javascript
tags: [array,math]
cover: red-lake
excerpt: Learn how to work with arrays of numbers in JavaScript, performing common math operations such as sum, average, product and more.
listed: t... | code_snippets | ||
bd9a45e9-345a-4462-accb-ddabc857dfa8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/numeric-array-math-operations.md | unknown | 27e7b0ad-af18-4ef8-9b74-7a85bf2253b4 | 3 | SemanticChunker@1.0.0 | 481a0ae52a153c0eb0154582c74deaef5360286fba71682ee95998d4d0d7719c | [Sum of an array > Product of an array]
## Product of an array
The product of an array is the result of **multiplying all the numbers in the array together**.
You can use `Array.prototype.reduce()` to multiply each value with an accumulator, initialized with a value of `1`.
```js
const prod = (...arr) =>
[...arr].... | unknown | unknown | [Sum of an array > Product of an array]
## Product of an array
The product of an array is the result of **multiplying all the numbers in the array together**.
You can use `Array.prototype.reduce()` to multiply each value with an accumulator, initialized with a value of `1`.
```js
const prod = (...arr) =>
[...arr].... | [Sum of an array > Product of an array]
## Product of an array
The product of an array is the result of **multiplying all the numbers in the array together**.
You can use `Array.prototype.reduce()` to multiply each value with an accumulator, initialized with a value of `1`.
```js
const prod = (...arr) =>
[...arr].... | code_snippets | ||
eaca61a8-7acb-41d1-b4d2-99dae480d608 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/numeric-array-math-operations.md | unknown | 27e7b0ad-af18-4ef8-9b74-7a85bf2253b4 | 2 | SemanticChunker@1.0.0 | 07fa11b4db995ed29741a391240c60a4a725f814a696fa316194626d682ecaff | [Sum of an array > Average of an array]
## Average of an array
The average of an array is the result of adding all the numbers in the array together and then **dividing the resulting sum by the length of the array**.
You can use the same technique as summing an array, then use `Array.prototype.length` to divide the ... | unknown | unknown | [Sum of an array > Average of an array]
## Average of an array
The average of an array is the result of adding all the numbers in the array together and then **dividing the resulting sum by the length of the array**.
You can use the same technique as summing an array, then use `Array.prototype.length` to divide the ... | [Sum of an array > Average of an array]
## Average of an array
The average of an array is the result of adding all the numbers in the array together and then **dividing the resulting sum by the length of the array**.
You can use the same technique as summing an array, then use `Array.prototype.length` to divide the ... | code_snippets | ||
ec5d3b43-878f-48c2-a4d7-af663f2b5a6b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/numeric-array-math-operations.md | unknown | 27e7b0ad-af18-4ef8-9b74-7a85bf2253b4 | 6 | SemanticChunker@1.0.0 | 3e9adf114b7a97c7f04817c92cf3d4cb20e04706333ea166f188d1b3c722b3ad | [Sum of an array > Standard deviation of an array]
## Standard deviation of an array
The standard deviation of an array is a measure of **how much the values in the array differ from the mean**. In order to calculate the standard deviation, you need to calculate the mean of the array, then calculate the difference be... | unknown | unknown | [Sum of an array > Standard deviation of an array]
## Standard deviation of an array
The standard deviation of an array is a measure of **how much the values in the array differ from the mean**. In order to calculate the standard deviation, you need to calculate the mean of the array, then calculate the difference be... | [Sum of an array > Standard deviation of an array]
## Standard deviation of an array
The standard deviation of an array is a measure of **how much the values in the array differ from the mean**. In order to calculate the standard deviation, you need to calculate the mean of the array, then calculate the difference be... | code_snippets | ||
f94a25a8-1f3f-4c3c-9c3b-7979b2d8a6c5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/numeric-array-math-operations.md | unknown | 27e7b0ad-af18-4ef8-9b74-7a85bf2253b4 | 5 | SemanticChunker@1.0.0 | 928525e677dd77598a2c54773ea8827555672ddfe55ad2b9504af030fc593525 | [Sum of an array > Weighted average of an array]
## Weighted average of an array
The weighted average of an array is the result of **multiplying each number in the array by a corresponding weight**, adding the results together and then **dividing the resulting sum by the sum of the weights**.
You can use `Array.prot... | unknown | unknown | [Sum of an array > Weighted average of an array]
## Weighted average of an array
The weighted average of an array is the result of **multiplying each number in the array by a corresponding weight**, adding the results together and then **dividing the resulting sum by the sum of the weights**.
You can use `Array.prot... | [Sum of an array > Weighted average of an array]
## Weighted average of an array
The weighted average of an array is the result of **multiplying each number in the array by a corresponding weight**, adding the results together and then **dividing the resulting sum by the sum of the weights**.
You can use `Array.prot... | code_snippets | ||
54c78b2d-611d-4e98-9e3a-4bf82026397b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/normalize-line-endings.md | unknown | 200f01e8-f842-4308-bd03-617cee57300a | 0 | SemanticChunker@1.0.0 | 8cf558b588b3ee2c9de42f9e24075883b03f1a34e2da74f1a8c7cfe17e2e70f6 | ---
title: Normalize line endings in a JavaScript string
shortTitle: Normalize line endings
language: javascript
tags: [string,regexp]
cover: red-light
excerpt: Having trouble with inconsistent line endings in your strings? Normalize them with this handy JavaScript function!
listed: true
dateModified: 2024-05-24
---
H... | unknown | unknown | ---
title: Normalize line endings in a JavaScript string
shortTitle: Normalize line endings
language: javascript
tags: [string,regexp]
cover: red-light
excerpt: Having trouble with inconsistent line endings in your strings? Normalize them with this handy JavaScript function!
listed: true
dateModified: 2024-05-24
---
H... | ---
title: Normalize line endings in a JavaScript string
shortTitle: Normalize line endings
language: javascript
tags: [string,regexp]
cover: red-light
excerpt: Having trouble with inconsistent line endings in your strings? Normalize them with this handy JavaScript function!
listed: true
dateModified: 2024-05-24
---
H... | code_snippets | ||
3a7d3d56-dfa0-4682-9f04-ac53e18e4ed2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nodejs-test-module-introduction.md | unknown | f36322fa-ee94-4d91-977b-71cb4227fe80 | 0 | SemanticChunker@1.0.0 | 33fcb345c80881a0e93ad74bc7d0d12bc7c4dbbc9d81c1c31db12c7075039465 | ---
title: Introduction to the Node.js test module
shortTitle: Node.js test module introduction
language: javascript
tags: [node,testing]
cover: contemporary-desk
excerpt: The Node.js test module is a new testing tool that's still in its early stages. Learn more about it in this short introduction.
listed: true
dateMod... | unknown | unknown | ---
title: Introduction to the Node.js test module
shortTitle: Node.js test module introduction
language: javascript
tags: [node,testing]
cover: contemporary-desk
excerpt: The Node.js test module is a new testing tool that's still in its early stages. Learn more about it in this short introduction.
listed: true
dateMod... | ---
title: Introduction to the Node.js test module
shortTitle: Node.js test module introduction
language: javascript
tags: [node,testing]
cover: contemporary-desk
excerpt: The Node.js test module is a new testing tool that's still in its early stages. Learn more about it in this short introduction.
listed: true
dateMod... | code_snippets | ||
bf47ccc3-d7e5-4bef-95f8-ecb377775e90 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nodejs-test-module-introduction.md | unknown | f36322fa-ee94-4d91-977b-71cb4227fe80 | 1 | SemanticChunker@1.0.0 | 93838f2920c04feb84cf6473981873c8445fd930f12e3914c9e81bcf6f330cc1 | ```js
import test from 'node:test';
import assert from 'node:assert/strict';
test('my test', () => {
assert.strictEqual(1, 1);
});
```
This is pretty simple, but how does one **run the tests from the command line**? Contrary to most other tools, you don't need to create a new entry under your `package.json`'s `scrip... | unknown | unknown | ```js
import test from 'node:test';
import assert from 'node:assert/strict';
test('my test', () => {
assert.strictEqual(1, 1);
});
```
This is pretty simple, but how does one **run the tests from the command line**? Contrary to most other tools, you don't need to create a new entry under your `package.json`'s `scrip... | ```js
import test from 'node:test';
import assert from 'node:assert/strict';
test('my test', () => {
assert.strictEqual(1, 1);
});
```
This is pretty simple, but how does one **run the tests from the command line**? Contrary to most other tools, you don't need to create a new entry under your `package.json`'s `scrip... | code_snippets | ||
e63e8e50-c7b2-4891-9eb5-bb1bdb9f1567 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/nodejs-test-module-introduction.md | unknown | f36322fa-ee94-4d91-977b-71cb4227fe80 | 2 | SemanticChunker@1.0.0 | 79f4f79083c81b254239a6c1103bbe480ea8ab44a221612218bff1d406f51348 | While all of this sounds pretty good, you might be wondering what a **real-world example** looks like. I cooked up a little function that mutates an array of numbers and returns a value just to demonstrate. The logic is not particularly complex or interesting, but it's enough to take the module for a spin. Let's have a... | unknown | unknown | While all of this sounds pretty good, you might be wondering what a **real-world example** looks like. I cooked up a little function that mutates an array of numbers and returns a value just to demonstrate. The logic is not particularly complex or interesting, but it's enough to take the module for a spin. Let's have a... | While all of this sounds pretty good, you might be wondering what a **real-world example** looks like. I cooked up a little function that mutates an array of numbers and returns a value just to demonstrate. The logic is not particularly complex or interesting, but it's enough to take the module for a spin. Let's have a... | code_snippets | ||
139015dd-c8f1-460e-9476-88d97c6e6ef5 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-is-even-odd.md | unknown | cede8a70-c0d8-4460-8ebc-02c1f944b592 | 0 | SemanticChunker@1.0.0 | 7382c167826d09c18d0c7925004fd296103e3235e09aa4cabc36407d357395e5 | ---
title: How can I check if a number is even or odd using JavaScript?
shortTitle: Check if a number is even or odd
language: javascript
tags: [math]
cover: by-the-lighthouse
excerpt: Check if a number is even or odd using JavaScript using the modulo operator or bitwise AND operator.
listed: true
dateModified: 2023-10... | unknown | unknown | ---
title: How can I check if a number is even or odd using JavaScript?
shortTitle: Check if a number is even or odd
language: javascript
tags: [math]
cover: by-the-lighthouse
excerpt: Check if a number is even or odd using JavaScript using the modulo operator or bitwise AND operator.
listed: true
dateModified: 2023-10... | ---
title: How can I check if a number is even or odd using JavaScript?
shortTitle: Check if a number is even or odd
language: javascript
tags: [math]
cover: by-the-lighthouse
excerpt: Check if a number is even or odd using JavaScript using the modulo operator or bitwise AND operator.
listed: true
dateModified: 2023-10... | code_snippets | ||
3eef7405-d620-4d3b-8886-7702f16ec772 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-is-even-odd.md | unknown | cede8a70-c0d8-4460-8ebc-02c1f944b592 | 1 | SemanticChunker@1.0.0 | 880e5cb8cd11b1d094fa22d8bac998305f90711ac344d4beafa7b6597f1cdeb6 | [Using the modulo operator]
## Using the modulo operator
The **modulo operator** (`%`) returns the **remainder of a division operation**. Given that, we can check if a number is even or odd by dividing it by `2` and checking the remainder. If the remainder is `0`, the number is even, otherwise it's odd.
```js
const ... | unknown | unknown | [Using the modulo operator]
## Using the modulo operator
The **modulo operator** (`%`) returns the **remainder of a division operation**. Given that, we can check if a number is even or odd by dividing it by `2` and checking the remainder. If the remainder is `0`, the number is even, otherwise it's odd.
```js
const ... | [Using the modulo operator]
## Using the modulo operator
The **modulo operator** (`%`) returns the **remainder of a division operation**. Given that, we can check if a number is even or odd by dividing it by `2` and checking the remainder. If the remainder is `0`, the number is even, otherwise it's odd.
```js
const ... | code_snippets | ||
ca25b5cd-8f79-49dc-ab1d-f07beef6abd2 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-is-even-odd.md | unknown | cede8a70-c0d8-4460-8ebc-02c1f944b592 | 2 | SemanticChunker@1.0.0 | 1207f443bc2814b381777427007d92287cf19142aa83213ebbdf08d74fcc80c2 | [Using the modulo operator > Using the bitwise AND operator]
## Using the bitwise AND operator
The **bitwise AND operator** (`&`) returns `1` if both bits are `1`, otherwise it returns `0`. The binary representation of an even number always ends with `0`, while the binary representation of an odd number always ends w... | unknown | unknown | [Using the modulo operator > Using the bitwise AND operator]
## Using the bitwise AND operator
The **bitwise AND operator** (`&`) returns `1` if both bits are `1`, otherwise it returns `0`. The binary representation of an even number always ends with `0`, while the binary representation of an odd number always ends w... | [Using the modulo operator > Using the bitwise AND operator]
## Using the bitwise AND operator
The **bitwise AND operator** (`&`) returns `1` if both bits are `1`, otherwise it returns `0`. The binary representation of an even number always ends with `0`, while the binary representation of an odd number always ends w... | code_snippets | ||
ff031ad0-8c16-49ab-ab0a-72bff0bc253d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-is-even-odd.md | unknown | cede8a70-c0d8-4460-8ebc-02c1f944b592 | 3 | SemanticChunker@1.0.0 | 59d5cc04162210d825201659c40a14cc6fe833909ddb82003d5bdedd38cc0c83 | [Using the bitwise AND operator > Notes]
### Notes
- While both approaches work, the modulo operator is more readable and should be preferred.
- Apart from these two approaches, other bitwise operators, such as the bitwise XOR operator (`^`), can also be used to check if a number is even or odd. | unknown | unknown | [Using the bitwise AND operator > Notes]
### Notes
- While both approaches work, the modulo operator is more readable and should be preferred.
- Apart from these two approaches, other bitwise operators, such as the bitwise XOR operator (`^`), can also be used to check if a number is even or odd. | [Using the bitwise AND operator > Notes]
### Notes
- While both approaches work, the modulo operator is more readable and should be preferred.
- Apart from these two approaches, other bitwise operators, such as the bitwise XOR operator (`^`), can also be used to check if a number is even or odd. | code_snippets | ||
0915ef54-d610-4642-9fd6-6e55007c1dae | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-formatting.md | unknown | f0195e26-1deb-4584-8e3f-b6d05a66ed99 | 1 | SemanticChunker@1.0.0 | 1d6de416bdb70a7a39ececb59b19fb48847f53c548224f5db57aa794d853a9fb | [Fixed-point notation without trailing zeros]
## Fixed-point notation without trailing zeros
In **fixed-point notation**, a number is represented with a fixed number of digits after the decimal point. However, we often want to **remove trailing zeros** from the result.
In order to do so, we can use `Number.prototype... | unknown | unknown | [Fixed-point notation without trailing zeros]
## Fixed-point notation without trailing zeros
In **fixed-point notation**, a number is represented with a fixed number of digits after the decimal point. However, we often want to **remove trailing zeros** from the result.
In order to do so, we can use `Number.prototype... | [Fixed-point notation without trailing zeros]
## Fixed-point notation without trailing zeros
In **fixed-point notation**, a number is represented with a fixed number of digits after the decimal point. However, we often want to **remove trailing zeros** from the result.
In order to do so, we can use `Number.prototype... | code_snippets | ||
22c7bb17-a1b2-4813-a15b-92241e984127 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-formatting.md | unknown | f0195e26-1deb-4584-8e3f-b6d05a66ed99 | 9 | SemanticChunker@1.0.0 | 3d220473b4e7e899a3f4a421f8c2864ee2f3d9f3322f1449e98af6ceb5c4a41e | [Fixed-point notation without trailing zeros > Pad number with leading zeros]
## Pad number with leading zeros
Last but not least, you might need to **pad a number with leading zeros** to a specific length. We can use `String.prototype.padStart()` to pad the number to the specified length, after converting it to a st... | unknown | unknown | [Fixed-point notation without trailing zeros > Pad number with leading zeros]
## Pad number with leading zeros
Last but not least, you might need to **pad a number with leading zeros** to a specific length. We can use `String.prototype.padStart()` to pad the number to the specified length, after converting it to a st... | [Fixed-point notation without trailing zeros > Pad number with leading zeros]
## Pad number with leading zeros
Last but not least, you might need to **pad a number with leading zeros** to a specific length. We can use `String.prototype.padStart()` to pad the number to the specified length, after converting it to a st... | code_snippets | ||
41c44930-616a-4755-b141-9b5ae400e030 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-formatting.md | unknown | f0195e26-1deb-4584-8e3f-b6d05a66ed99 | 3 | SemanticChunker@1.0.0 | 46b3fa754936b05b028555138458b8d20412d66e2363c4a3239eb02417ad5f7a | [Fixed-point notation without trailing zeros > Format duration]
## Format duration
Converting a number of milliseconds to a **human-readable format** is a matter of dividing the number by the appropriate values and creating a string for each value. In the following snippet, we'll use an object that contains the appro... | unknown | unknown | [Fixed-point notation without trailing zeros > Format duration]
## Format duration
Converting a number of milliseconds to a **human-readable format** is a matter of dividing the number by the appropriate values and creating a string for each value. In the following snippet, we'll use an object that contains the appro... | [Fixed-point notation without trailing zeros > Format duration]
## Format duration
Converting a number of milliseconds to a **human-readable format** is a matter of dividing the number by the appropriate values and creating a string for each value. In the following snippet, we'll use an object that contains the appro... | code_snippets | ||
47fa7600-ed3e-4178-a85c-b7baf76aa0a1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-formatting.md | unknown | f0195e26-1deb-4584-8e3f-b6d05a66ed99 | 8 | SemanticChunker@1.0.0 | 8b64f6c47dab18639c639bee4eaf4b13a2f90ad54a8ea25f1b1aa05709c84b82 | [Locale-sensitive number formatting > Number to ordinal suffix]
### Number to ordinal suffix
Converting a number to its **ordinal form** (e.g. `1` to `1st`, `2` to `2nd`, `3` to `3rd`, etc.) is also fairly simple, using `Intl.PluralRules`. We can use `Intl.PluralRules.prototype.select()` to get the correct **pluraliz... | unknown | unknown | [Locale-sensitive number formatting > Number to ordinal suffix]
### Number to ordinal suffix
Converting a number to its **ordinal form** (e.g. `1` to `1st`, `2` to `2nd`, `3` to `3rd`, etc.) is also fairly simple, using `Intl.PluralRules`. We can use `Intl.PluralRules.prototype.select()` to get the correct **pluraliz... | [Locale-sensitive number formatting > Number to ordinal suffix]
### Number to ordinal suffix
Converting a number to its **ordinal form** (e.g. `1` to `1st`, `2` to `2nd`, `3` to `3rd`, etc.) is also fairly simple, using `Intl.PluralRules`. We can use `Intl.PluralRules.prototype.select()` to get the correct **pluraliz... | code_snippets | ||
91162366-f609-436f-a7c9-00ca6cc1bd9f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-formatting.md | unknown | f0195e26-1deb-4584-8e3f-b6d05a66ed99 | 0 | SemanticChunker@1.0.0 | 60f4e6361ce4527f3c11141624098272de1aa91ed0130c557da5f81b7e0da12e | ---
title: Formatting numeric values in JavaScript
shortTitle: Number formatting
language: javascript
tags: [number,date]
cover: white-chapel
excerpt: Learn common number formatting operations, such as rounding, padding, optional decimal marks, currency, seconds, bytes, and more.
listed: true
dateModified: 2024-02-14
-... | unknown | unknown | ---
title: Formatting numeric values in JavaScript
shortTitle: Number formatting
language: javascript
tags: [number,date]
cover: white-chapel
excerpt: Learn common number formatting operations, such as rounding, padding, optional decimal marks, currency, seconds, bytes, and more.
listed: true
dateModified: 2024-02-14
-... | ---
title: Formatting numeric values in JavaScript
shortTitle: Number formatting
language: javascript
tags: [number,date]
cover: white-chapel
excerpt: Learn common number formatting operations, such as rounding, padding, optional decimal marks, currency, seconds, bytes, and more.
listed: true
dateModified: 2024-02-14
-... | code_snippets | ||
92020e15-b123-48ba-a063-9cbe92299817 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-formatting.md | unknown | f0195e26-1deb-4584-8e3f-b6d05a66ed99 | 7 | SemanticChunker@1.0.0 | 8b52c5ecaa1f79ada48a6232125bb60c4c43775edd8b1b584792c313216229d3 | [Locale-sensitive number formatting > Number to currency string]
### Number to currency string
When working with **currency**, it's important to use the appropriate formatting. Luckily, JavaScript's `Intl.NumberFormat` makes this easy, allowing us to format numbers as currency strings. All we have to do is specify th... | unknown | unknown | [Locale-sensitive number formatting > Number to currency string]
### Number to currency string
When working with **currency**, it's important to use the appropriate formatting. Luckily, JavaScript's `Intl.NumberFormat` makes this easy, allowing us to format numbers as currency strings. All we have to do is specify th... | [Locale-sensitive number formatting > Number to currency string]
### Number to currency string
When working with **currency**, it's important to use the appropriate formatting. Luckily, JavaScript's `Intl.NumberFormat` makes this easy, allowing us to format numbers as currency strings. All we have to do is specify th... | code_snippets | ||
a840515b-b68b-4893-b1e2-0d06cf03af8e | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-formatting.md | unknown | f0195e26-1deb-4584-8e3f-b6d05a66ed99 | 4 | SemanticChunker@1.0.0 | 37aa73d93dabae095ec72f0a8225bd4d42f2c5833018aaf598a367775eb2e0dd | [Format duration > Number of seconds to ISO format]
### Number of seconds to ISO format
Similarly, formatting the number of seconds to **ISO format** is also a handful of divisions away. However, we need to handle the **sign** separately.
We can use `Array.prototype.map()` in combination with `Math.floor()` and `Str... | unknown | unknown | [Format duration > Number of seconds to ISO format]
### Number of seconds to ISO format
Similarly, formatting the number of seconds to **ISO format** is also a handful of divisions away. However, we need to handle the **sign** separately.
We can use `Array.prototype.map()` in combination with `Math.floor()` and `Str... | [Format duration > Number of seconds to ISO format]
### Number of seconds to ISO format
Similarly, formatting the number of seconds to **ISO format** is also a handful of divisions away. However, we need to handle the **sign** separately.
We can use `Array.prototype.map()` in combination with `Math.floor()` and `Str... | code_snippets | ||
af32cefa-6b6a-462f-8e44-2c9878ead5d4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-formatting.md | unknown | f0195e26-1deb-4584-8e3f-b6d05a66ed99 | 5 | SemanticChunker@1.0.0 | cf5eb6578caf66a8c11a7788302dae2400faf4f617d1b689ffc9ac2452257a1d | [Fixed-point notation without trailing zeros > Locale-sensitive number formatting]
## Locale-sensitive number formatting
Formatting a number to a **locale-sensitive string** is also easy using `Number.prototype.toLocaleString()`. This method allows us to format numbers using the local number format separators.
```js... | unknown | unknown | [Fixed-point notation without trailing zeros > Locale-sensitive number formatting]
## Locale-sensitive number formatting
Formatting a number to a **locale-sensitive string** is also easy using `Number.prototype.toLocaleString()`. This method allows us to format numbers using the local number format separators.
```js... | [Fixed-point notation without trailing zeros > Locale-sensitive number formatting]
## Locale-sensitive number formatting
Formatting a number to a **locale-sensitive string** is also easy using `Number.prototype.toLocaleString()`. This method allows us to format numbers using the local number format separators.
```js... | code_snippets | ||
db2e0acd-92d3-489b-8146-740bf86e900f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-formatting.md | unknown | f0195e26-1deb-4584-8e3f-b6d05a66ed99 | 2 | SemanticChunker@1.0.0 | 1636b4e3eb092cfb0d061763adc20bf31e45d8001b4292c423f661edc8ef71c3 | [Fixed-point notation without trailing zeros > Round number to given precision]
## Round number to given precision
Rounding a number to a **specific number of decimal places** is pretty common. We can use `Math.round()` and template literals to round the number to the specified number of digits. Omitting the second a... | unknown | unknown | [Fixed-point notation without trailing zeros > Round number to given precision]
## Round number to given precision
Rounding a number to a **specific number of decimal places** is pretty common. We can use `Math.round()` and template literals to round the number to the specified number of digits. Omitting the second a... | [Fixed-point notation without trailing zeros > Round number to given precision]
## Round number to given precision
Rounding a number to a **specific number of decimal places** is pretty common. We can use `Math.round()` and template literals to round the number to the specified number of digits. Omitting the second a... | code_snippets | ||
de4dd839-500f-43a6-820a-664cc8eec7b3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/number-formatting.md | unknown | f0195e26-1deb-4584-8e3f-b6d05a66ed99 | 6 | SemanticChunker@1.0.0 | 18928f20c95072c08610ffb3fa265e3897187db3a5d15f942de88987ddfedeab | [Locale-sensitive number formatting > Number to decimal mark]
### Number to decimal mark
If we want to format a number to a specific locale, we can pass the locale as the first argument to `Number.prototype.toLocaleString()`. For example, here's how to format a number to use the **decimal mark**, using the `en-US` lo... | unknown | unknown | [Locale-sensitive number formatting > Number to decimal mark]
### Number to decimal mark
If we want to format a number to a specific locale, we can pass the locale as the first argument to `Number.prototype.toLocaleString()`. For example, here's how to format a number to use the **decimal mark**, using the `en-US` lo... | [Locale-sensitive number formatting > Number to decimal mark]
### Number to decimal mark
If we want to format a number to a specific locale, we can pass the locale as the first argument to `Number.prototype.toLocaleString()`. For example, here's how to format a number to use the **decimal mark**, using the `en-US` lo... | code_snippets | ||
b7553232-c288-4615-a2d7-31e2261146f6 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/offset-array-elements.md | unknown | adc0bd0f-c62c-40df-8bd7-5f97ca255c54 | 0 | SemanticChunker@1.0.0 | 118560d2f53230c921df32622f88f90aef4a2bd3ac47098c791892b15e770a0a | ---
title: Offset elements in a JavaScript array
shortTitle: Offset array elements
language: javascript
tags: [array]
cover: interior-10
excerpt: Ever needed to move some elements to the end of an array? Here's a simple way to do it.
listed: true
dateModified: 2024-08-09
---
Have you ever needed to **move some element... | unknown | unknown | ---
title: Offset elements in a JavaScript array
shortTitle: Offset array elements
language: javascript
tags: [array]
cover: interior-10
excerpt: Ever needed to move some elements to the end of an array? Here's a simple way to do it.
listed: true
dateModified: 2024-08-09
---
Have you ever needed to **move some element... | ---
title: Offset elements in a JavaScript array
shortTitle: Offset array elements
language: javascript
tags: [array]
cover: interior-10
excerpt: Ever needed to move some elements to the end of an array? Here's a simple way to do it.
listed: true
dateModified: 2024-08-09
---
Have you ever needed to **move some element... | code_snippets | ||
fa26cdca-64c7-43bc-a204-20256b723666 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-is-triple-equals.md | unknown | 07839fad-9773-4521-b8ff-82e20a844f0c | 0 | SemanticChunker@1.0.0 | 71aa99b9535cc49535bb74cab76d28a4f28b746848bf45a98d0b115093fc5442 | ---
title: What's the difference between Object.is() and the triple equals operator in JavaScript?
shortTitle: Object.is() vs triple equals operator
language: javascript
tags: [object,type]
cover: rocky-mountains
excerpt: "`Object.is()` and the triple equals operator (`===`) can both be used for equality checking in Ja... | unknown | unknown | ---
title: What's the difference between Object.is() and the triple equals operator in JavaScript?
shortTitle: Object.is() vs triple equals operator
language: javascript
tags: [object,type]
cover: rocky-mountains
excerpt: "`Object.is()` and the triple equals operator (`===`) can both be used for equality checking in Ja... | ---
title: What's the difference between Object.is() and the triple equals operator in JavaScript?
shortTitle: Object.is() vs triple equals operator
language: javascript
tags: [object,type]
cover: rocky-mountains
excerpt: "`Object.is()` and the triple equals operator (`===`) can both be used for equality checking in Ja... | code_snippets | ||
42cbd435-13b9-4936-8ce8-eeb2f3e8ccf7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/observable-proxy.md | unknown | 5e9631bd-ca79-4ced-811c-18970f3635f0 | 1 | SemanticChunker@1.0.0 | ba9ff1482bc7aad4e99b703eb755e3d508f76f125ed0b5a426da4e6c40f872b1 | While this code is pretty simple, it can be easily extend to handle more complex use cases, such as **nested objects** or **arrays**. It can be even used to create an observable store, similar to Redux. Give it a try and see how far you can take it!
@[Further reading](/js/s/event-driven-vanilla-js-signals) | unknown | unknown | While this code is pretty simple, it can be easily extend to handle more complex use cases, such as **nested objects** or **arrays**. It can be even used to create an observable store, similar to Redux. Give it a try and see how far you can take it!
@[Further reading](/js/s/event-driven-vanilla-js-signals) | While this code is pretty simple, it can be easily extend to handle more complex use cases, such as **nested objects** or **arrays**. It can be even used to create an observable store, similar to Redux. Give it a try and see how far you can take it!
@[Further reading](/js/s/event-driven-vanilla-js-signals) | code_snippets | ||
e7d62322-4a22-4821-a864-527b1c378b73 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/observable-proxy.md | unknown | 5e9631bd-ca79-4ced-811c-18970f3635f0 | 0 | SemanticChunker@1.0.0 | 787a6476e64da9678a7f36767cdef4aeb892f5e568275981d0c3f69e963b782c | ---
title: Using a Proxy to implement the Observable pattern
shortTitle: Observable Proxy
language: javascript
tags: [proxy]
cover: city-view
excerpt: Use the Proxy object to implement the Observable pattern in JavaScript.
listed: true
dateModified: 2024-05-27
---
The **Observer pattern** is a design pattern where an ... | unknown | unknown | ---
title: Using a Proxy to implement the Observable pattern
shortTitle: Observable Proxy
language: javascript
tags: [proxy]
cover: city-view
excerpt: Use the Proxy object to implement the Observable pattern in JavaScript.
listed: true
dateModified: 2024-05-27
---
The **Observer pattern** is a design pattern where an ... | ---
title: Using a Proxy to implement the Observable pattern
shortTitle: Observable Proxy
language: javascript
tags: [proxy]
cover: city-view
excerpt: Use the Proxy object to implement the Observable pattern in JavaScript.
listed: true
dateModified: 2024-05-27
---
The **Observer pattern** is a design pattern where an ... | code_snippets | ||
0163fd7f-5e1e-4442-9d0b-54657861ebd8 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-has-value-or-key.md | unknown | 930f7943-86a4-468d-a823-15f8e1c336ab | 2 | SemanticChunker@1.0.0 | 50d9d814a1e7e1a35a6ee319fef3052fed8ef2b0a48c207879348327ac2241d9 | [Check if an object has a given value > Check if an object has a given key]
## Check if an object has a given key
Checking if an object has a given key is equally as easy, using `Object.keys()` instead of `Object.values()`. Then, you can use `Array.prototype.includes()` to check if the target key is included in the k... | unknown | unknown | [Check if an object has a given value > Check if an object has a given key]
## Check if an object has a given key
Checking if an object has a given key is equally as easy, using `Object.keys()` instead of `Object.values()`. Then, you can use `Array.prototype.includes()` to check if the target key is included in the k... | [Check if an object has a given value > Check if an object has a given key]
## Check if an object has a given key
Checking if an object has a given key is equally as easy, using `Object.keys()` instead of `Object.values()`. Then, you can use `Array.prototype.includes()` to check if the target key is included in the k... | code_snippets | ||
5f512732-16a5-4fd1-96d0-996235c71073 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-has-value-or-key.md | unknown | 930f7943-86a4-468d-a823-15f8e1c336ab | 3 | SemanticChunker@1.0.0 | 93a7194cc19c9128f86f18400028e9ffcd1e99a83766a440d076c9dbb76174d3 | [Check if an object has a given key > Accounting for nested keys]
### Accounting for nested keys
Checking for **nested keys** is a bit more complex, but can be done with a little ingenuity.
Given an array of keys, you can use `Array.prototype.every()` to sequentially check the keys to the internal **depth of the obj... | unknown | unknown | [Check if an object has a given key > Accounting for nested keys]
### Accounting for nested keys
Checking for **nested keys** is a bit more complex, but can be done with a little ingenuity.
Given an array of keys, you can use `Array.prototype.every()` to sequentially check the keys to the internal **depth of the obj... | [Check if an object has a given key > Accounting for nested keys]
### Accounting for nested keys
Checking for **nested keys** is a bit more complex, but can be done with a little ingenuity.
Given an array of keys, you can use `Array.prototype.every()` to sequentially check the keys to the internal **depth of the obj... | code_snippets | ||
ad99d90c-8885-4f14-ab96-40c4bfc4cede | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-has-value-or-key.md | unknown | 930f7943-86a4-468d-a823-15f8e1c336ab | 0 | SemanticChunker@1.0.0 | 1f25e36241fb7055bcc52aed36798b1a595ee5062c90a56ecd0c5af9b240a8fb | ---
title: Check if a JavaScript object has a given value or key
shortTitle: Object has value or key
language: javascript
tags: [object]
cover: plant-corner
excerpt: When working with objects, you'll often need to check if a value or key exists, and these snippets will show you how to do just that.
listed: true
dateMod... | unknown | unknown | ---
title: Check if a JavaScript object has a given value or key
shortTitle: Object has value or key
language: javascript
tags: [object]
cover: plant-corner
excerpt: When working with objects, you'll often need to check if a value or key exists, and these snippets will show you how to do just that.
listed: true
dateMod... | ---
title: Check if a JavaScript object has a given value or key
shortTitle: Object has value or key
language: javascript
tags: [object]
cover: plant-corner
excerpt: When working with objects, you'll often need to check if a value or key exists, and these snippets will show you how to do just that.
listed: true
dateMod... | code_snippets | ||
dac8255b-2371-48d4-ba91-676f9f4a48e9 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-has-value-or-key.md | unknown | 930f7943-86a4-468d-a823-15f8e1c336ab | 1 | SemanticChunker@1.0.0 | 54b5590a37e11a59c5ed702bd64b2af53b0c0407f5022f556f6a9485251148a2 | [Check if an object has a given value]
## Check if an object has a given value
In order to check if an object has a given value, you can use `Object.values()` to get all the values of the object. Then, use `Array.prototype.includes()` to check if the target value is included in the values array.
```js
const hasValue... | unknown | unknown | [Check if an object has a given value]
## Check if an object has a given value
In order to check if an object has a given value, you can use `Object.values()` to get all the values of the object. Then, use `Array.prototype.includes()` to check if the target value is included in the values array.
```js
const hasValue... | [Check if an object has a given value]
## Check if an object has a given value
In order to check if an object has a given value, you can use `Object.values()` to get all the values of the object. Then, use `Array.prototype.includes()` to check if the target value is included in the values array.
```js
const hasValue... | code_snippets | ||
7481b247-4bf8-49b5-b09d-4726ba97187b | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/on-scroll-stop.md | unknown | 19cff540-2110-42ca-9866-b69071a41667 | 0 | SemanticChunker@1.0.0 | 644489f262f84d53e31e6f233e8c1cd8ae694a27d0b60f36a38ca3a79e696b32 | ---
title: Use JavaScript to listen and handle scroll stop events
shortTitle: Handle scroll stop
language: javascript
tags: [browser,event]
cover: half-trees
excerpt: Use some clever JavaScript tricks to listen for and handle scroll stop events in the browser.
listed: true
dateModified: 2024-03-02
---
Listening for sc... | unknown | unknown | ---
title: Use JavaScript to listen and handle scroll stop events
shortTitle: Handle scroll stop
language: javascript
tags: [browser,event]
cover: half-trees
excerpt: Use some clever JavaScript tricks to listen for and handle scroll stop events in the browser.
listed: true
dateModified: 2024-03-02
---
Listening for sc... | ---
title: Use JavaScript to listen and handle scroll stop events
shortTitle: Handle scroll stop
language: javascript
tags: [browser,event]
cover: half-trees
excerpt: Use some clever JavaScript tricks to listen for and handle scroll stop events in the browser.
listed: true
dateModified: 2024-03-02
---
Listening for sc... | code_snippets | ||
7efebbf9-e4aa-4c21-be20-d50918c6e697 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/on-scroll-stop.md | unknown | 19cff540-2110-42ca-9866-b69071a41667 | 1 | SemanticChunker@1.0.0 | b8578ea836e4a0f6ef485e55f47bc5e125f7d6886978e505bf85a69d765016e3 | ```js
const onScrollStop = callback => {
let isScrolling;
window.addEventListener(
'scroll',
e => {
clearTimeout(isScrolling);
isScrolling = setTimeout(() => {
callback();
}, 150);
},
false
);
};
onScrollStop(() => {
console.log('The user has stopped scrolling');
}); // Logs when the user has stopped scrol... | unknown | unknown | ```js
const onScrollStop = callback => {
let isScrolling;
window.addEventListener(
'scroll',
e => {
clearTimeout(isScrolling);
isScrolling = setTimeout(() => {
callback();
}, 150);
},
false
);
};
onScrollStop(() => {
console.log('The user has stopped scrolling');
}); // Logs when the user has stopped scrol... | ```js
const onScrollStop = callback => {
let isScrolling;
window.addEventListener(
'scroll',
e => {
clearTimeout(isScrolling);
isScrolling = setTimeout(() => {
callback();
}, 150);
},
false
);
};
onScrollStop(() => {
console.log('The user has stopped scrolling');
}); // Logs when the user has stopped scrol... | code_snippets | ||
a5a82805-b76b-4b55-8854-a15bd4117150 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-array-proxy.md | unknown | 7b2e1dc1-0dfe-4cd4-ae65-a22ba6e7b6f6 | 0 | SemanticChunker@1.0.0 | 7a14bd604b9f7c652a2f102f7183f53f13e5e0dc425e29682f7c4f30b0a0eeb2 | ---
title: Can I use an object as an array without modifying it in JavaScript?
shortTitle: Object as array
language: javascript
tags: [proxy,object,array,iterator,pattern]
cover: birds
excerpt: Learn how you can leverage the Proxy object to use a JavaScript object the same way as you would use a regular array.
listed: ... | unknown | unknown | ---
title: Can I use an object as an array without modifying it in JavaScript?
shortTitle: Object as array
language: javascript
tags: [proxy,object,array,iterator,pattern]
cover: birds
excerpt: Learn how you can leverage the Proxy object to use a JavaScript object the same way as you would use a regular array.
listed: ... | ---
title: Can I use an object as an array without modifying it in JavaScript?
shortTitle: Object as array
language: javascript
tags: [proxy,object,array,iterator,pattern]
cover: birds
excerpt: Learn how you can leverage the Proxy object to use a JavaScript object the same way as you would use a regular array.
listed: ... | code_snippets | ||
ba3af89f-4069-447b-b5dc-0c2850d69847 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-array-proxy.md | unknown | 7b2e1dc1-0dfe-4cd4-ae65-a22ba6e7b6f6 | 1 | SemanticChunker@1.0.0 | 30f9398b03fbfc9f11836893a0b7eeb004b2eca6a1a6c5a84d6a1f54ef0a849b | ```js
const toKeyedArray = obj => {
const methods = {
map(target) {
return callback =>
Object.keys(target).map(key => callback(target[key], key, target));
},
reduce(target) {
return (callback, accumulator) =>
Object.keys(target).reduce(
(acc, key) => callback(acc, target[key], key, target),
accumulator
);
}... | unknown | unknown | ```js
const toKeyedArray = obj => {
const methods = {
map(target) {
return callback =>
Object.keys(target).map(key => callback(target[key], key, target));
},
reduce(target) {
return (callback, accumulator) =>
Object.keys(target).reduce(
(acc, key) => callback(acc, target[key], key, target),
accumulator
);
}... | ```js
const toKeyedArray = obj => {
const methods = {
map(target) {
return callback =>
Object.keys(target).map(key => callback(target[key], key, target));
},
reduce(target) {
return (callback, accumulator) =>
Object.keys(target).reduce(
(acc, key) => callback(acc, target[key], key, target),
accumulator
);
}... | code_snippets | ||
2ee8a66b-c744-4e46-9a74-69b8a871fdee | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/pad-string.md | unknown | 64cc455c-ebc9-4790-814d-6dd7494d2352 | 0 | SemanticChunker@1.0.0 | d48e329466541fc1873477b68c76cd20cc6657a6185cf0adebe0e987a0eb26dd | ---
title: Pad a string with a character
shortTitle: Pad string
language: javascript
tags: [string]
cover: bridge-over-road
excerpt: Pad a string on both sides with the specified character, if it's shorter than the specified length.
listed: true
dateModified: 2024-08-14
---
Oftentimes, when working with string, especi... | unknown | unknown | ---
title: Pad a string with a character
shortTitle: Pad string
language: javascript
tags: [string]
cover: bridge-over-road
excerpt: Pad a string on both sides with the specified character, if it's shorter than the specified length.
listed: true
dateModified: 2024-08-14
---
Oftentimes, when working with string, especi... | ---
title: Pad a string with a character
shortTitle: Pad string
language: javascript
tags: [string]
cover: bridge-over-road
excerpt: Pad a string on both sides with the specified character, if it's shorter than the specified length.
listed: true
dateModified: 2024-08-14
---
Oftentimes, when working with string, especi... | code_snippets | ||
16dab4dd-2622-41e6-9b15-3aefe1853bfa | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 15 | SemanticChunker@1.0.0 | 008ad0cfe4fcee709fddfe0f69a6c6b369fc6fd9cdf7421faf553d3af5e71fcf | [Nullish coalescing operator > Nullish assignment operator]
### Nullish assignment operator
The nullish assignment operator (`??=`) assigns the right-hand operand to the left-hand operand only if the left-hand operand is `null` or `undefined`.
```js
let a = null;
let b = 5;
a ??= b; // a is now 5 (a was null)
let c ... | unknown | unknown | [Nullish coalescing operator > Nullish assignment operator]
### Nullish assignment operator
The nullish assignment operator (`??=`) assigns the right-hand operand to the left-hand operand only if the left-hand operand is `null` or `undefined`.
```js
let a = null;
let b = 5;
a ??= b; // a is now 5 (a was null)
let c ... | [Nullish coalescing operator > Nullish assignment operator]
### Nullish assignment operator
The nullish assignment operator (`??=`) assigns the right-hand operand to the left-hand operand only if the left-hand operand is `null` or `undefined`.
```js
let a = null;
let b = 5;
a ??= b; // a is now 5 (a was null)
let c ... | code_snippets | ||
24101362-5460-43ac-8afd-6ef9071b353f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 10 | SemanticChunker@1.0.0 | d95091ea866407ca18e941d61047f8de1490b1ad2adaeeda8a66f00a4e0f4d86 | [Assignment operator > Ternary operator]
## Ternary operator
The ternary operator (`?`) is a shorthand for an `if...else` statement. It takes three operands:
- A condition to evaluate
- The value to return if the condition is `true`
- The value to return if the condition is `false`
```js
const age = 18;
const canVo... | unknown | unknown | [Assignment operator > Ternary operator]
## Ternary operator
The ternary operator (`?`) is a shorthand for an `if...else` statement. It takes three operands:
- A condition to evaluate
- The value to return if the condition is `true`
- The value to return if the condition is `false`
```js
const age = 18;
const canVo... | [Assignment operator > Ternary operator]
## Ternary operator
The ternary operator (`?`) is a shorthand for an `if...else` statement. It takes three operands:
- A condition to evaluate
- The value to return if the condition is `true`
- The value to return if the condition is `false`
```js
const age = 18;
const canVo... | code_snippets | ||
33a5c646-f89d-4242-a97b-e4443bb22dc0 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 12 | SemanticChunker@1.0.0 | c0d9eca477cbf0703972ce07e58172b995918ad90e045074d1e2850182be1c43 | [Assignment operator > Bitwise operators]
## Bitwise operators
Bitwise operators perform operations on the binary representations of numbers. They are not commonly used in JavaScript, but they can be useful in certain situations:
- `&`: bitwise AND
- `|`: bitwise OR
- `^`: bitwise XOR
- `~`: bitwise NOT
- `<<`: left... | unknown | unknown | [Assignment operator > Bitwise operators]
## Bitwise operators
Bitwise operators perform operations on the binary representations of numbers. They are not commonly used in JavaScript, but they can be useful in certain situations:
- `&`: bitwise AND
- `|`: bitwise OR
- `^`: bitwise XOR
- `~`: bitwise NOT
- `<<`: left... | [Assignment operator > Bitwise operators]
## Bitwise operators
Bitwise operators perform operations on the binary representations of numbers. They are not commonly used in JavaScript, but they can be useful in certain situations:
- `&`: bitwise AND
- `|`: bitwise OR
- `^`: bitwise XOR
- `~`: bitwise NOT
- `<<`: left... | code_snippets | ||
3e8e1f95-aa93-48d2-8656-955e10ef30e4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 5 | SemanticChunker@1.0.0 | 0657873ac466e883e15b131c2e3a5e2ca885b60705e5c0b28a1f2f1feaaeaacb | [Math operators > Increment & decrement operators]
### Increment & decrement operators
The increment (`++`) and decrement (`--`) operators are shorthand for adding or subtracting 1 from a variable. They can be used in two ways:
- **Prefix**: `++a` or `--a` (increments/decrements the variable before using it)
- **Pos... | unknown | unknown | [Math operators > Increment & decrement operators]
### Increment & decrement operators
The increment (`++`) and decrement (`--`) operators are shorthand for adding or subtracting 1 from a variable. They can be used in two ways:
- **Prefix**: `++a` or `--a` (increments/decrements the variable before using it)
- **Pos... | [Math operators > Increment & decrement operators]
### Increment & decrement operators
The increment (`++`) and decrement (`--`) operators are shorthand for adding or subtracting 1 from a variable. They can be used in two ways:
- **Prefix**: `++a` or `--a` (increments/decrements the variable before using it)
- **Pos... | code_snippets | ||
3e97383c-aebb-49de-9057-9ce03fd761e7 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 17 | SemanticChunker@1.0.0 | 51ecd8b9a3e767074ba537ec26166d751433870875c79d7256cca87194b3c812 | [Assignment operator > Optional chaining operator]
## Optional chaining operator
The optional chaining operator (`?.`) allows you to safely access deeply nested properties of an object without having to check if each property in the chain exists. If any property in the chain is `null` or `undefined`, it returns `unde... | unknown | unknown | [Assignment operator > Optional chaining operator]
## Optional chaining operator
The optional chaining operator (`?.`) allows you to safely access deeply nested properties of an object without having to check if each property in the chain exists. If any property in the chain is `null` or `undefined`, it returns `unde... | [Assignment operator > Optional chaining operator]
## Optional chaining operator
The optional chaining operator (`?.`) allows you to safely access deeply nested properties of an object without having to check if each property in the chain exists. If any property in the chain is `null` or `undefined`, it returns `unde... | code_snippets | ||
582dcc23-2ddc-4294-b06b-4cc528bd4c3f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 14 | SemanticChunker@1.0.0 | 93440a190469644de13bc7ce44c5de3b3795c3f3150ea24eebe7b578add83b75 | [Assignment operator > Nullish coalescing operator]
## Nullish coalescing operator
The nullish coalescing operator (`??`) returns the right-hand operand when the left-hand operand is `null` or `undefined`. It is useful for providing default values.
```js
const a = null;
const b = 5;
const c = a ?? b; // 5 (a is null... | unknown | unknown | [Assignment operator > Nullish coalescing operator]
## Nullish coalescing operator
The nullish coalescing operator (`??`) returns the right-hand operand when the left-hand operand is `null` or `undefined`. It is useful for providing default values.
```js
const a = null;
const b = 5;
const c = a ?? b; // 5 (a is null... | [Assignment operator > Nullish coalescing operator]
## Nullish coalescing operator
The nullish coalescing operator (`??`) returns the right-hand operand when the left-hand operand is `null` or `undefined`. It is useful for providing default values.
```js
const a = null;
const b = 5;
const c = a ?? b; // 5 (a is null... | code_snippets | ||
6bb5eef3-5a68-4497-ac9c-b02fb86dd061 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 18 | SemanticChunker@1.0.0 | fe0ed59a27b0d00dc96f703cdb79fddf30b304396802db22ef4989d37b7b4aff | [Assignment operator > Comma operator]
## Comma operator
The comma operator (`,`) evaluates each of its operands (from left to right) and returns the value of the last operand.
```js
const a = (1, 2, 3); // a is 3
``` | unknown | unknown | [Assignment operator > Comma operator]
## Comma operator
The comma operator (`,`) evaluates each of its operands (from left to right) and returns the value of the last operand.
```js
const a = (1, 2, 3); // a is 3
``` | [Assignment operator > Comma operator]
## Comma operator
The comma operator (`,`) evaluates each of its operands (from left to right) and returns the value of the last operand.
```js
const a = (1, 2, 3); // a is 3
``` | code_snippets | ||
6ce9aa79-300d-4680-be43-1f33d87a67be | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 16 | SemanticChunker@1.0.0 | 6610f8feab154d09ceb54c7894b6688723cd1239dd285b1b131851469b578d6e | [Assignment operator > Property access operator]
## Property access operator
The property access operator (`.`) is used to access properties of objects. It can also be used to call methods on objects.
```js
const obj = { a: 1 };
const value = obj.a; // 1
``` | unknown | unknown | [Assignment operator > Property access operator]
## Property access operator
The property access operator (`.`) is used to access properties of objects. It can also be used to call methods on objects.
```js
const obj = { a: 1 };
const value = obj.a; // 1
``` | [Assignment operator > Property access operator]
## Property access operator
The property access operator (`.`) is used to access properties of objects. It can also be used to call methods on objects.
```js
const obj = { a: 1 };
const value = obj.a; // 1
``` | code_snippets | ||
81cf00bb-eb55-413b-a4e9-7989d056ccb4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 1 | SemanticChunker@1.0.0 | d01e59e6522988fb7f62f88a9eb23099f73849599d09391d609a3a1b39926cae | [Assignment operator > Equality comparison operators]
## Equality comparison operators
JavaScript equality comes in two flavors:
- `==` (loose equality) & `!=` (loose inequality)
- `===` (strict equality) & `!==` (strict inequality)
```js
// Loose equality
10 == '10'; // true
10 != '10'; // false
// Strict equalit... | unknown | unknown | [Assignment operator > Equality comparison operators]
## Equality comparison operators
JavaScript equality comes in two flavors:
- `==` (loose equality) & `!=` (loose inequality)
- `===` (strict equality) & `!==` (strict inequality)
```js
// Loose equality
10 == '10'; // true
10 != '10'; // false
// Strict equalit... | [Assignment operator > Equality comparison operators]
## Equality comparison operators
JavaScript equality comes in two flavors:
- `==` (loose equality) & `!=` (loose inequality)
- `===` (strict equality) & `!==` (strict inequality)
```js
// Loose equality
10 == '10'; // true
10 != '10'; // false
// Strict equalit... | code_snippets | ||
8fd3f10e-18f7-4da5-966e-a302764e46fa | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 3 | SemanticChunker@1.0.0 | 39450cf80d4ef0541eb49354a06f26c11b654e220b50d4874da98965df2bf2ff | [Assignment operator > Math operators]
## Math operators
Math operators are pretty much exactly what you'd expect. They perform basic arithmetic operations:
- `+`: addition (binary) or casting to number (unary)
- `-`: subtraction (binary) or negation (unary)
- `*`: multiplication
- `/`: division
- `%`: modulo (remai... | unknown | unknown | [Assignment operator > Math operators]
## Math operators
Math operators are pretty much exactly what you'd expect. They perform basic arithmetic operations:
- `+`: addition (binary) or casting to number (unary)
- `-`: subtraction (binary) or negation (unary)
- `*`: multiplication
- `/`: division
- `%`: modulo (remai... | [Assignment operator > Math operators]
## Math operators
Math operators are pretty much exactly what you'd expect. They perform basic arithmetic operations:
- `+`: addition (binary) or casting to number (unary)
- `-`: subtraction (binary) or negation (unary)
- `*`: multiplication
- `/`: division
- `%`: modulo (remai... | code_snippets | ||
9095011e-0d11-4cb6-8a41-b5cb116b1014 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 8 | SemanticChunker@1.0.0 | 703402a0e0793a582d7337999d186fa0afc5a40bbdb17169eada9f61996bb950 | [Logical operators > Logical assignment operators]
### Logical assignment operators
Logical assignment operators combine logical operations with assignment. They are shorthand for the longer forms:
- `&&=`: logical AND assignment (assigns the value if the left operand is truthy)
- `||=`: logical OR assignment (assig... | unknown | unknown | [Logical operators > Logical assignment operators]
### Logical assignment operators
Logical assignment operators combine logical operations with assignment. They are shorthand for the longer forms:
- `&&=`: logical AND assignment (assigns the value if the left operand is truthy)
- `||=`: logical OR assignment (assig... | [Logical operators > Logical assignment operators]
### Logical assignment operators
Logical assignment operators combine logical operations with assignment. They are shorthand for the longer forms:
- `&&=`: logical AND assignment (assigns the value if the left operand is truthy)
- `||=`: logical OR assignment (assig... | code_snippets | ||
9d3323d6-ffdb-43cb-8291-5f74bc249377 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 7 | SemanticChunker@1.0.0 | 81c0d88e4bc1ae0de8d360b59ecbd6273c4805d53777aa1e5164890126288965 | [Assignment operator > Logical operators]
## Logical operators
Logical operators are used to combine or negate boolean values:
- `&&`: logical AND
- `||`: logical OR
- `!`: logical NOT
```js
const a = true;
const b = false;
const c = a && b; // false (both must be true)
const d = a || b; // true (at least one must ... | unknown | unknown | [Assignment operator > Logical operators]
## Logical operators
Logical operators are used to combine or negate boolean values:
- `&&`: logical AND
- `||`: logical OR
- `!`: logical NOT
```js
const a = true;
const b = false;
const c = a && b; // false (both must be true)
const d = a || b; // true (at least one must ... | [Assignment operator > Logical operators]
## Logical operators
Logical operators are used to combine or negate boolean values:
- `&&`: logical AND
- `||`: logical OR
- `!`: logical NOT
```js
const a = true;
const b = false;
const c = a && b; // false (both must be true)
const d = a || b; // true (at least one must ... | code_snippets | ||
a06bb4e9-56f1-4be0-ac60-4c991c3f5e2d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 13 | SemanticChunker@1.0.0 | 669b11591c18bd36f90091f86e0095778324f0876d77b32b6fa8644e7a62529e | [Bitwise operators > Bitwise assignment operators]
### Bitwise assignment operators
Bitwise assignment operators combine bitwise operations with assignment. They are shorthand for the longer forms:
- `&=`: bitwise AND assignment
- `|=`: bitwise OR assignment
- `^=`: bitwise XOR assignment
- `<<=`: left shift assignme... | unknown | unknown | [Bitwise operators > Bitwise assignment operators]
### Bitwise assignment operators
Bitwise assignment operators combine bitwise operations with assignment. They are shorthand for the longer forms:
- `&=`: bitwise AND assignment
- `|=`: bitwise OR assignment
- `^=`: bitwise XOR assignment
- `<<=`: left shift assignme... | [Bitwise operators > Bitwise assignment operators]
### Bitwise assignment operators
Bitwise assignment operators combine bitwise operations with assignment. They are shorthand for the longer forms:
- `&=`: bitwise AND assignment
- `|=`: bitwise OR assignment
- `^=`: bitwise XOR assignment
- `<<=`: left shift assignme... | code_snippets | ||
ab52dfe3-9757-4696-9547-2e1467565cc1 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 4 | SemanticChunker@1.0.0 | a88c3064a64c3f859b8a8c52c6488d3a9608bd4110e7a2382de02dbc184e663d | [Math operators > Math assignment operators]
### Math assignment operators
A similar, set of operators combines assignment (`=`) with the math operators. These are shorthand for the longer forms:
- `+=`: addition assignment
- `-=`: subtraction assignment
- `*=`: multiplication assignment
- `/=`: division assignment
... | unknown | unknown | [Math operators > Math assignment operators]
### Math assignment operators
A similar, set of operators combines assignment (`=`) with the math operators. These are shorthand for the longer forms:
- `+=`: addition assignment
- `-=`: subtraction assignment
- `*=`: multiplication assignment
- `/=`: division assignment
... | [Math operators > Math assignment operators]
### Math assignment operators
A similar, set of operators combines assignment (`=`) with the math operators. These are shorthand for the longer forms:
- `+=`: addition assignment
- `-=`: subtraction assignment
- `*=`: multiplication assignment
- `/=`: division assignment
... | code_snippets | ||
aedf0276-9f0b-47d8-99cc-fce08fbde270 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 0 | SemanticChunker@1.0.0 | bd3948d4c5c8c0dc8db54a49e121b4f5de6cf9711ec42489eff12f1ace251393 | ---
title: JavaScript Operator Cheatsheet
shortTitle: Operator Cheatsheet
language: javascript
tags: [type,math,comparison]
cover: dying-flowers
excerpt: Quick reference for JavaScript operators.
listed: true
dateModified: 2025-05-07
---
> [!IMPORTANT]
>
> This article serves as a **quick reference for JavaScript's sy... | unknown | unknown | ---
title: JavaScript Operator Cheatsheet
shortTitle: Operator Cheatsheet
language: javascript
tags: [type,math,comparison]
cover: dying-flowers
excerpt: Quick reference for JavaScript operators.
listed: true
dateModified: 2025-05-07
---
> [!IMPORTANT]
>
> This article serves as a **quick reference for JavaScript's sy... | ---
title: JavaScript Operator Cheatsheet
shortTitle: Operator Cheatsheet
language: javascript
tags: [type,math,comparison]
cover: dying-flowers
excerpt: Quick reference for JavaScript operators.
listed: true
dateModified: 2025-05-07
---
> [!IMPORTANT]
>
> This article serves as a **quick reference for JavaScript's sy... | code_snippets | ||
bffe58e6-09bc-4f35-934e-c6da3fadc643 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 9 | SemanticChunker@1.0.0 | bdf687b4f5a33f8cb45e3b8dafca0de0ac3bdf9542059b4acdae6292ce943af9 | [Logical operators > Double negation operator]
### Double negation operator
The double NOT (`!!`) is not technically an operator, but provides a way to convert a value to its boolean equivalent. It negates the value twice, effectively converting it to a boolean.
```js
const str = 'Hello';
const isNotEmpty = !!str; /... | unknown | unknown | [Logical operators > Double negation operator]
### Double negation operator
The double NOT (`!!`) is not technically an operator, but provides a way to convert a value to its boolean equivalent. It negates the value twice, effectively converting it to a boolean.
```js
const str = 'Hello';
const isNotEmpty = !!str; /... | [Logical operators > Double negation operator]
### Double negation operator
The double NOT (`!!`) is not technically an operator, but provides a way to convert a value to its boolean equivalent. It negates the value twice, effectively converting it to a boolean.
```js
const str = 'Hello';
const isNotEmpty = !!str; /... | code_snippets | ||
d8710b66-6811-459e-ae02-83e5b6a8c0c3 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 2 | SemanticChunker@1.0.0 | 92d658e3a80e4e0ffa406b84b58f8bfdd658657ece4e59046ba5c93aa9faf352 | [Assignment operator > Comparison operators]
## Comparison operators
Comparison operators compare two values, much like in math:
- `>`: greater than
- `<`: less than
- `>=`: greater than or equal to
- `<=`: less than or equal to
```js
const a = 5;
const b = 10;
a > b; // false
a < b; // true
a >= b; // false
a <= b... | unknown | unknown | [Assignment operator > Comparison operators]
## Comparison operators
Comparison operators compare two values, much like in math:
- `>`: greater than
- `<`: less than
- `>=`: greater than or equal to
- `<=`: less than or equal to
```js
const a = 5;
const b = 10;
a > b; // false
a < b; // true
a >= b; // false
a <= b... | [Assignment operator > Comparison operators]
## Comparison operators
Comparison operators compare two values, much like in math:
- `>`: greater than
- `<`: less than
- `>=`: greater than or equal to
- `<=`: less than or equal to
```js
const a = 5;
const b = 10;
a > b; // false
a < b; // true
a >= b; // false
a <= b... | code_snippets | ||
e854c27d-ed53-4ddb-8aba-9dc03178213d | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 11 | SemanticChunker@1.0.0 | 3476b577b9e22ff9d27a3a65c6d5ab4c2d389b6e144ce7e1458a55af33d41d50 | [Assignment operator > Spread operator]
## Spread operator
The spread operator (`...`) is used to expand an iterable (like an array or object) into its individual elements. It can be used in function calls, array literals, and object literals.
```js
const arr = [1, 2, 3];
const newArr = [...arr, 4, 5]; // [1, 2, 3, ... | unknown | unknown | [Assignment operator > Spread operator]
## Spread operator
The spread operator (`...`) is used to expand an iterable (like an array or object) into its individual elements. It can be used in function calls, array literals, and object literals.
```js
const arr = [1, 2, 3];
const newArr = [...arr, 4, 5]; // [1, 2, 3, ... | [Assignment operator > Spread operator]
## Spread operator
The spread operator (`...`) is used to expand an iterable (like an array or object) into its individual elements. It can be used in function calls, array literals, and object literals.
```js
const arr = [1, 2, 3];
const newArr = [...arr, 4, 5]; // [1, 2, 3, ... | code_snippets | ||
f02e8a1e-1c7f-4dbc-9397-65ddc8300057 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 19 | SemanticChunker@1.0.0 | 2eb57b08c3306d0e0e59f1f7c925a77d7fc3fe2ab84caab70a202d7fe7251f1d | [Assignment operator > Arrow function operator]
## Arrow function operator
While not technically an operator, it's often confused with one. The arrow function syntax (`=>`) is a shorthand for writing function expressions. It allows you to create anonymous functions in a more concise way.
```js
const add = (a, b) => ... | unknown | unknown | [Assignment operator > Arrow function operator]
## Arrow function operator
While not technically an operator, it's often confused with one. The arrow function syntax (`=>`) is a shorthand for writing function expressions. It allows you to create anonymous functions in a more concise way.
```js
const add = (a, b) => ... | [Assignment operator > Arrow function operator]
## Arrow function operator
While not technically an operator, it's often confused with one. The arrow function syntax (`=>`) is a shorthand for writing function expressions. It allows you to create anonymous functions in a more concise way.
```js
const add = (a, b) => ... | code_snippets | ||
f66417b5-9459-4f7d-b563-915159275483 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/operator-cheatsheet.md | unknown | 8fcb37ef-2441-4990-aa7e-9c84dc1ce9a0 | 6 | SemanticChunker@1.0.0 | 4f7e562920a745dec6d846574f49f3cac80732a13588622e0d9c3d671a6f27da | [Assignment operator > String concatenation operator]
## String concatenation operator
Apart from other usage mentioned above, the `+` operator can also be used to concatenate strings.
```js
const str1 = 'Hello';
const str2 = 'World';
const greeting = str1 + ' ' + str2; // 'Hello World'
``` | unknown | unknown | [Assignment operator > String concatenation operator]
## String concatenation operator
Apart from other usage mentioned above, the `+` operator can also be used to concatenate strings.
```js
const str1 = 'Hello';
const str2 = 'World';
const greeting = str1 + ' ' + str2; // 'Hello World'
``` | [Assignment operator > String concatenation operator]
## String concatenation operator
Apart from other usage mentioned above, the `+` operator can also be used to concatenate strings.
```js
const str1 = 'Hello';
const str2 = 'World';
const greeting = str1 + ' ' + str2; // 'Hello World'
``` | code_snippets | ||
17152369-39f0-4aeb-afa3-72e0f6bf4290 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/numeric-separator.md | unknown | 2ef4c91c-a556-45d0-b717-c0c90a5809a8 | 0 | SemanticChunker@1.0.0 | 7599e8a9fea826d3b758011dfec6deb79b880e25474198da7729e2cc42dfb253 | ---
title: JavaScript's numeric separators explained
shortTitle: Numeric separators explained
language: javascript
tags: [number,math]
cover: coffee-drip
excerpt: Numeric separators are a somewhat lesser-known JavaScript syntactic sugar that can make working with large constants a lot easier.
listed: true
dateModified:... | unknown | unknown | ---
title: JavaScript's numeric separators explained
shortTitle: Numeric separators explained
language: javascript
tags: [number,math]
cover: coffee-drip
excerpt: Numeric separators are a somewhat lesser-known JavaScript syntactic sugar that can make working with large constants a lot easier.
listed: true
dateModified:... | ---
title: JavaScript's numeric separators explained
shortTitle: Numeric separators explained
language: javascript
tags: [number,math]
cover: coffee-drip
excerpt: Numeric separators are a somewhat lesser-known JavaScript syntactic sugar that can make working with large constants a lot easier.
listed: true
dateModified:... | code_snippets | ||
5cf880b1-32fd-49b1-ae00-28aa2da914f4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-comparison.md | unknown | 5502e785-81f6-40ba-a835-4c24b7b3c7e3 | 2 | SemanticChunker@1.0.0 | 9f331ab569e422c32a2a8fac702bfd35b898f194efbf8cc6ca94c9e08086e11e | [Equality comparison > JSON.stringify]
## JSON.stringify
`JSON.stringify()` often comes up as the solution to this problem. While it can be useful in some situations, comparing the serialized strings can have its own **pitfalls**. The most common of these has to do with similar, but not equal, values that result in t... | unknown | unknown | [Equality comparison > JSON.stringify]
## JSON.stringify
`JSON.stringify()` often comes up as the solution to this problem. While it can be useful in some situations, comparing the serialized strings can have its own **pitfalls**. The most common of these has to do with similar, but not equal, values that result in t... | [Equality comparison > JSON.stringify]
## JSON.stringify
`JSON.stringify()` often comes up as the solution to this problem. While it can be useful in some situations, comparing the serialized strings can have its own **pitfalls**. The most common of these has to do with similar, but not equal, values that result in t... | code_snippets | ||
63bd43ed-6053-4a8b-a2b1-26729e34f74c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-comparison.md | unknown | 5502e785-81f6-40ba-a835-4c24b7b3c7e3 | 1 | SemanticChunker@1.0.0 | 8456de95053a7c90562f6d1f222d724c6822d8ce950857c1e7302112fdbeea5c | [Equality comparison]
## Equality comparison
Even though two different objects can have the **same properties with equal values**, they are not considered equal when compared using either the loose or strict equality operators (`==` or `===`). This is because arrays and objects in JavaScript are **compared by referen... | unknown | unknown | [Equality comparison]
## Equality comparison
Even though two different objects can have the **same properties with equal values**, they are not considered equal when compared using either the loose or strict equality operators (`==` or `===`). This is because arrays and objects in JavaScript are **compared by referen... | [Equality comparison]
## Equality comparison
Even though two different objects can have the **same properties with equal values**, they are not considered equal when compared using either the loose or strict equality operators (`==` or `===`). This is because arrays and objects in JavaScript are **compared by referen... | code_snippets | ||
7462f22d-a29c-4be5-a821-7161c20d9f64 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-comparison.md | unknown | 5502e785-81f6-40ba-a835-4c24b7b3c7e3 | 4 | SemanticChunker@1.0.0 | faf1eaa71715b22e0d9c733e3456ef01ec2e3ac61c3416360d921c8f03083720 | [Equality comparison > Deep equality comparison]
```js
const equals = (a, b) => {
if (a === b) return true;
if (a instanceof Date && b instanceof Date)
return a.getTime() === b.getTime();
if (!a || !b || (typeof a !== 'object' && typeof b !== 'object'))
return a === b;
if (a.prototype !== b.prototype) return ... | unknown | unknown | [Equality comparison > Deep equality comparison]
```js
const equals = (a, b) => {
if (a === b) return true;
if (a instanceof Date && b instanceof Date)
return a.getTime() === b.getTime();
if (!a || !b || (typeof a !== 'object' && typeof b !== 'object'))
return a === b;
if (a.prototype !== b.prototype) return ... | [Equality comparison > Deep equality comparison]
```js
const equals = (a, b) => {
if (a === b) return true;
if (a instanceof Date && b instanceof Date)
return a.getTime() === b.getTime();
if (!a || !b || (typeof a !== 'object' && typeof b !== 'object'))
return a === b;
if (a.prototype !== b.prototype) return ... | code_snippets | ||
d04fa479-1d73-41d7-ae47-9b7ba457be9f | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-comparison.md | unknown | 5502e785-81f6-40ba-a835-4c24b7b3c7e3 | 0 | SemanticChunker@1.0.0 | 12e1b3427447f29d9f32edafff4975491ce206a85d63814530a42869936bed67 | ---
title: How do I compare two objects in JavaScript?
shortTitle: Object comparison
language: javascript
tags: [object,comparison,recursion]
cover: blue-lake
excerpt: Learn how you can compare two objects in JavaScript using various different techniques.
listed: true
dateModified: 2024-07-10
--- | unknown | unknown | ---
title: How do I compare two objects in JavaScript?
shortTitle: Object comparison
language: javascript
tags: [object,comparison,recursion]
cover: blue-lake
excerpt: Learn how you can compare two objects in JavaScript using various different techniques.
listed: true
dateModified: 2024-07-10
--- | ---
title: How do I compare two objects in JavaScript?
shortTitle: Object comparison
language: javascript
tags: [object,comparison,recursion]
cover: blue-lake
excerpt: Learn how you can compare two objects in JavaScript using various different techniques.
listed: true
dateModified: 2024-07-10
--- | code_snippets | ||
d837ae4b-7cc8-4104-991e-25a8eb21b550 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/object-comparison.md | unknown | 5502e785-81f6-40ba-a835-4c24b7b3c7e3 | 3 | SemanticChunker@1.0.0 | e05bb78103ce2ac6338153500d773d8d8724ae5a58549df831a5c5e167114d72 | [Equality comparison > Deep equality comparison]
## Deep equality comparison
As it turns out, comparing two objects is not trivial. This is the reason why shallow or **deep equality comparison** helper functions are so common. These usually use recursion to deeply compare two objects, accounting for most scenarios su... | unknown | unknown | [Equality comparison > Deep equality comparison]
## Deep equality comparison
As it turns out, comparing two objects is not trivial. This is the reason why shallow or **deep equality comparison** helper functions are so common. These usually use recursion to deeply compare two objects, accounting for most scenarios su... | [Equality comparison > Deep equality comparison]
## Deep equality comparison
As it turns out, comparing two objects is not trivial. This is the reason why shallow or **deep equality comparison** helper functions are so common. These usually use recursion to deeply compare two objects, accounting for most scenarios su... | code_snippets | ||
362d17d2-b132-47d2-b8b0-c9a69a2848bb | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/partition-array.md | unknown | 79cd1a30-5f5e-4dee-afab-132e4d76645a | 2 | SemanticChunker@1.0.0 | 452d2ea1cb02e270519362806f1a8afbfa5ab45098dfde935f27ee1d4fdf9f6a | [Partition array into two > Partition array into multiple arrays]
## Partition array into multiple arrays
Partitioning an array into an arbitrary number of arrays, based on the return value of the provided function, poses a little more of a challenge. We can still make use of `Array.prototype.reduce()`, but instead o... | unknown | unknown | [Partition array into two > Partition array into multiple arrays]
## Partition array into multiple arrays
Partitioning an array into an arbitrary number of arrays, based on the return value of the provided function, poses a little more of a challenge. We can still make use of `Array.prototype.reduce()`, but instead o... | [Partition array into two > Partition array into multiple arrays]
## Partition array into multiple arrays
Partitioning an array into an arbitrary number of arrays, based on the return value of the provided function, poses a little more of a challenge. We can still make use of `Array.prototype.reduce()`, but instead o... | code_snippets | ||
4289ce16-ac72-4306-91a6-1b1c5a62e33c | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/partition-array.md | unknown | 79cd1a30-5f5e-4dee-afab-132e4d76645a | 0 | SemanticChunker@1.0.0 | adc905f2893eda395e66d9aa63fb75e42954f6dd4b90febd1b595307581a1db2 | ---
title: Partition a JavaScript array into two or more arrays based on a condition
shortTitle: Partition array
language: javascript
tags: [array,object]
cover: camping-trip
excerpt: Group array elements into two or more arrays arrays, depending on the provided function's return value.
listed: true
dateModified: 2024-... | unknown | unknown | ---
title: Partition a JavaScript array into two or more arrays based on a condition
shortTitle: Partition array
language: javascript
tags: [array,object]
cover: camping-trip
excerpt: Group array elements into two or more arrays arrays, depending on the provided function's return value.
listed: true
dateModified: 2024-... | ---
title: Partition a JavaScript array into two or more arrays based on a condition
shortTitle: Partition array
language: javascript
tags: [array,object]
cover: camping-trip
excerpt: Group array elements into two or more arrays arrays, depending on the provided function's return value.
listed: true
dateModified: 2024-... | code_snippets | ||
630992ef-2313-4fa7-b34b-8f7a7e7e46c4 | unknown | file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/partition-array.md | unknown | 79cd1a30-5f5e-4dee-afab-132e4d76645a | 1 | SemanticChunker@1.0.0 | cc0bdbc8940cafcb84d0a575cc2206db9560dc2a3ffded186292197b56377206 | [Partition array into two]
## Partition array into two
A two-partition is the simplest case and requires very little work. All we have to do is use `Array.prototype.reduce()` to create an **array of two arrays**. Then, we call the given function and use `Array.prototype.push()` to add elements for which `fn` returns ... | unknown | unknown | [Partition array into two]
## Partition array into two
A two-partition is the simplest case and requires very little work. All we have to do is use `Array.prototype.reduce()` to create an **array of two arrays**. Then, we call the given function and use `Array.prototype.push()` to add elements for which `fn` returns ... | [Partition array into two]
## Partition array into two
A two-partition is the simplest case and requires very little work. All we have to do is use `Array.prototype.reduce()` to create an **array of two arrays**. Then, we call the given function and use `Array.prototype.push()` to add elements for which `fn` returns ... | code_snippets |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.