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
098167f9-e93c-473a-b951-205c6ff28d07
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/test-driven-development-intro.md
unknown
5ae4c920-316c-4ebd-a11d-63ece09144ac
3
SemanticChunker@1.0.0
e5e9349e76f0d649986d6824844997ce7e1aa11bfe2e3c4705cc5b363bccf994
[What is TDD? > Tooling] I especially like the [`test.each()`](https://vitest.dev/api/#test-each) and [`describe.each()`](https://vitest.dev/api/#describe-each) functions, which allow you to **run the same test with different parameters**, sparing you the hassle of repeating the same assertions over and over again. `...
unknown
unknown
[What is TDD? > Tooling] I especially like the [`test.each()`](https://vitest.dev/api/#test-each) and [`describe.each()`](https://vitest.dev/api/#describe-each) functions, which allow you to **run the same test with different parameters**, sparing you the hassle of repeating the same assertions over and over again. `...
[What is TDD? > Tooling] I especially like the [`test.each()`](https://vitest.dev/api/#test-each) and [`describe.each()`](https://vitest.dev/api/#describe-each) functions, which allow you to **run the same test with different parameters**, sparing you the hassle of repeating the same assertions over and over again. `...
code_snippets
118e1f69-0901-4545-9aa5-e1201511bb6c
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/test-driven-development-intro.md
unknown
5ae4c920-316c-4ebd-a11d-63ece09144ac
6
SemanticChunker@1.0.0
7b6b96490a776e6347769ead044f58ff9b32b764647c3087ac0274468079241e
[Tooling > Higher confidence] ### Higher confidence One of the things I noticed as I went through the process was that I was pretty confident about my code. I knew that if I broke something, the tests would catch it. This is a great feeling to have, especially when you're working on a project that you're not entirely...
unknown
unknown
[Tooling > Higher confidence] ### Higher confidence One of the things I noticed as I went through the process was that I was pretty confident about my code. I knew that if I broke something, the tests would catch it. This is a great feeling to have, especially when you're working on a project that you're not entirely...
[Tooling > Higher confidence] ### Higher confidence One of the things I noticed as I went through the process was that I was pretty confident about my code. I knew that if I broke something, the tests would catch it. This is a great feeling to have, especially when you're working on a project that you're not entirely...
code_snippets
3070669e-7e4c-4dce-af72-c809138aed8a
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/test-driven-development-intro.md
unknown
5ae4c920-316c-4ebd-a11d-63ece09144ac
1
SemanticChunker@1.0.0
2c59b0ed0c03911bafbdf5f9adec08004eff1a32f49284dab2af56ac93fd7848
[What is TDD?] ## What is TDD? **Test-Driven Development**, often referred to as TDD, is a **software development methodology** that relies on writing tests before writing the actual code. The idea is to define the desired behavior of the code through tests and then write the code to achieve that behavior. This appro...
unknown
unknown
[What is TDD?] ## What is TDD? **Test-Driven Development**, often referred to as TDD, is a **software development methodology** that relies on writing tests before writing the actual code. The idea is to define the desired behavior of the code through tests and then write the code to achieve that behavior. This appro...
[What is TDD?] ## What is TDD? **Test-Driven Development**, often referred to as TDD, is a **software development methodology** that relies on writing tests before writing the actual code. The idea is to define the desired behavior of the code through tests and then write the code to achieve that behavior. This appro...
code_snippets
3cec2930-4ff8-4341-ab64-cfda82a093dc
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/test-driven-development-intro.md
unknown
5ae4c920-316c-4ebd-a11d-63ece09144ac
2
SemanticChunker@1.0.0
b99e2ce457f219efc2473e3ba15dfc707daaef348f760a63bd5accd5cec855b5
[What is TDD? > Tooling] ## Tooling I decided to use [Vitest](https://vitest.dev/) for this project. It's the tool I've settled on, after trying the likes of Jest and Mocha. It feels faster and, in my experience, it's easier to set up and configure than its counterparts. > [!TIP] > > I didn't really have to configur...
unknown
unknown
[What is TDD? > Tooling] ## Tooling I decided to use [Vitest](https://vitest.dev/) for this project. It's the tool I've settled on, after trying the likes of Jest and Mocha. It feels faster and, in my experience, it's easier to set up and configure than its counterparts. > [!TIP] > > I didn't really have to configur...
[What is TDD? > Tooling] ## Tooling I decided to use [Vitest](https://vitest.dev/) for this project. It's the tool I've settled on, after trying the likes of Jest and Mocha. It feels faster and, in my experience, it's easier to set up and configure than its counterparts. > [!TIP] > > I didn't really have to configur...
code_snippets
7a18bfb1-75a4-4ef8-8862-a95d3b722020
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/test-driven-development-intro.md
unknown
5ae4c920-316c-4ebd-a11d-63ece09144ac
4
SemanticChunker@1.0.0
ef0da555c66735776c399eebe2208dbbef1c4980d7c6382bf9d9906ef9223472
[What is TDD? > Tooling] describe('hexDigit', () => { it('should match hex digit', () => { expect(hexDigit).toMatchString('0'); expect(hexDigit).toMatchString('9'); expect(hexDigit).toMatchString('a'); expect(hexDigit).toMatchString('f'); expect(hexDigit).not.toMatchString('g'); expect(hexDigit).not.toMatchStri...
unknown
unknown
[What is TDD? > Tooling] describe('hexDigit', () => { it('should match hex digit', () => { expect(hexDigit).toMatchString('0'); expect(hexDigit).toMatchString('9'); expect(hexDigit).toMatchString('a'); expect(hexDigit).toMatchString('f'); expect(hexDigit).not.toMatchString('g'); expect(hexDigit).not.toMatchStri...
[What is TDD? > Tooling] describe('hexDigit', () => { it('should match hex digit', () => { expect(hexDigit).toMatchString('0'); expect(hexDigit).toMatchString('9'); expect(hexDigit).toMatchString('a'); expect(hexDigit).toMatchString('f'); expect(hexDigit).not.toMatchString('g'); expect(hexDigit).not.toMatchStri...
code_snippets
b75a44c2-55a9-4506-af45-51bd4a0c6baf
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/test-driven-development-intro.md
unknown
5ae4c920-316c-4ebd-a11d-63ece09144ac
5
SemanticChunker@1.0.0
1a6f8db6eb7e6ce6d8fbe59e6380164ccbb2c77ae023f410cd68004d1a677176
[What is TDD? > Tooling] It also puts you in the shoes of the user, instead of the library author – a perspective that can be hard to maintain otherwise. This means that you're **evaluating the tool from the perspective of usability**, instead of the traditional viewpoint of minimizing complexity when writing the code...
unknown
unknown
[What is TDD? > Tooling] It also puts you in the shoes of the user, instead of the library author – a perspective that can be hard to maintain otherwise. This means that you're **evaluating the tool from the perspective of usability**, instead of the traditional viewpoint of minimizing complexity when writing the code...
[What is TDD? > Tooling] It also puts you in the shoes of the user, instead of the library author – a perspective that can be hard to maintain otherwise. This means that you're **evaluating the tool from the perspective of usability**, instead of the traditional viewpoint of minimizing complexity when writing the code...
code_snippets
c540f7b8-d95f-4e03-90e1-9064ecd0f838
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/test-driven-development-intro.md
unknown
5ae4c920-316c-4ebd-a11d-63ece09144ac
8
SemanticChunker@1.0.0
25cc3aac9a38c5594ea9cb15e59506079ff5076fce9c998089889171ffb2b2c3
[What is TDD? > Takeaways] ## Takeaways I've been skeptical of TDD for years now, but there's nothing like true hands-on experience to shape one's opinion. Having heard of the benefits before, I can tell you that they're as described on the tin. _Would I use it again?_ Absolutely. In fact, I think that all my smalle...
unknown
unknown
[What is TDD? > Takeaways] ## Takeaways I've been skeptical of TDD for years now, but there's nothing like true hands-on experience to shape one's opinion. Having heard of the benefits before, I can tell you that they're as described on the tin. _Would I use it again?_ Absolutely. In fact, I think that all my smalle...
[What is TDD? > Takeaways] ## Takeaways I've been skeptical of TDD for years now, but there's nothing like true hands-on experience to shape one's opinion. Having heard of the benefits before, I can tell you that they're as described on the tin. _Would I use it again?_ Absolutely. In fact, I think that all my smalle...
code_snippets
cdbbe933-acfc-4752-8dac-ae64095575ab
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/test-driven-development-intro.md
unknown
5ae4c920-316c-4ebd-a11d-63ece09144ac
0
SemanticChunker@1.0.0
e0535618d0f08ceecb7d0dbef99df66ed8e55a9b233f4866072248bd83b66d81
--- title: Kickstart a JavaScript project with Test-Driven Development shortTitle: Test-Driven Development language: javascript tags: [webdev,testing] cover: succulent-5 excerpt: I recently built a project using Test-Driven Development (TDD) and it was a great experience. Here's why I think you should try it, too. list...
unknown
unknown
--- title: Kickstart a JavaScript project with Test-Driven Development shortTitle: Test-Driven Development language: javascript tags: [webdev,testing] cover: succulent-5 excerpt: I recently built a project using Test-Driven Development (TDD) and it was a great experience. Here's why I think you should try it, too. list...
--- title: Kickstart a JavaScript project with Test-Driven Development shortTitle: Test-Driven Development language: javascript tags: [webdev,testing] cover: succulent-5 excerpt: I recently built a project using Test-Driven Development (TDD) and it was a great experience. Here's why I think you should try it, too. list...
code_snippets
d8ead164-2104-414f-83cf-8e94311ada12
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/test-driven-development-intro.md
unknown
5ae4c920-316c-4ebd-a11d-63ece09144ac
7
SemanticChunker@1.0.0
2b4c101b7f1afe00cf22f6bde026c6eca3081276f0a15ce16346b9b14cf3ccd2
[Tooling > Higher confidence] This was especially true when one small change in a file broke the entire library at its core and I wouldn't have realized, because it was a pretty subtle mistake relating to spreading arguments in a function call. Ouch!
unknown
unknown
[Tooling > Higher confidence] This was especially true when one small change in a file broke the entire library at its core and I wouldn't have realized, because it was a pretty subtle mistake relating to spreading arguments in a function call. Ouch!
[Tooling > Higher confidence] This was especially true when one small change in a file broke the entire library at its core and I wouldn't have realized, because it was a pretty subtle mistake relating to spreading arguments in a function call. Ouch!
code_snippets
f3ac5b9b-f83b-48eb-b5f0-a27b4b979aab
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/test-driven-development-intro.md
unknown
5ae4c920-316c-4ebd-a11d-63ece09144ac
9
SemanticChunker@1.0.0
aa67d607e142afa51983e8372e9db13076bbed8f006e60666180a41685707002
[What is TDD? > Conclusion] ## Conclusion In conclusion, I found that TDD was a great way to write code. It helped me design what I wanted the library to do first, outline use-cases and the API, and gave me confidence in my code. It also made refactoring easier, as I could be sure that I hadn't broken anything. At t...
unknown
unknown
[What is TDD? > Conclusion] ## Conclusion In conclusion, I found that TDD was a great way to write code. It helped me design what I wanted the library to do first, outline use-cases and the API, and gave me confidence in my code. It also made refactoring easier, as I could be sure that I hadn't broken anything. At t...
[What is TDD? > Conclusion] ## Conclusion In conclusion, I found that TDD was a great way to write code. It helped me design what I wanted the library to do first, outline use-cases and the API, and gave me confidence in my code. It also made refactoring easier, as I could be sure that I hadn't broken anything. At t...
code_snippets
1372e4e7-e5ba-4370-a6e9-cda699284756
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/this.md
unknown
5e25958a-9e2b-4631-9642-5540160f69e2
4
SemanticChunker@1.0.0
5d209dd31ca0e6fb9fbb4f2eb3557142a1b3707681c0c10fddddcfdde71ccd8d
[What is `this`? > Arrow function context] ## Arrow function context In arrow functions, `this` retains the value of the enclosing lexical context's `this`. ```js const f = () => this; console.log(f() === window); // true const obj = { foo: function() { const baz = () => this; return baz(); }, bar: () => this...
unknown
unknown
[What is `this`? > Arrow function context] ## Arrow function context In arrow functions, `this` retains the value of the enclosing lexical context's `this`. ```js const f = () => this; console.log(f() === window); // true const obj = { foo: function() { const baz = () => this; return baz(); }, bar: () => this...
[What is `this`? > Arrow function context] ## Arrow function context In arrow functions, `this` retains the value of the enclosing lexical context's `this`. ```js const f = () => this; console.log(f() === window); // true const obj = { foo: function() { const baz = () => this; return baz(); }, bar: () => this...
code_snippets
1ab475b6-13e3-477c-8192-d3e9f59165a5
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/this.md
unknown
5e25958a-9e2b-4631-9642-5540160f69e2
3
SemanticChunker@1.0.0
9169822c867d08654de56c94d215130fdd14596e9a77b109b33bd520ecefdc90
[What is `this`? > Object context] ## Object context When a function is called as a method of an object, `this` refers to the object the method is called on. This applies to methods defined anywhere in the object's prototype chain (i.e. own and inherited methods). ```js const obj = { f: function() { return this; ...
unknown
unknown
[What is `this`? > Object context] ## Object context When a function is called as a method of an object, `this` refers to the object the method is called on. This applies to methods defined anywhere in the object's prototype chain (i.e. own and inherited methods). ```js const obj = { f: function() { return this; ...
[What is `this`? > Object context] ## Object context When a function is called as a method of an object, `this` refers to the object the method is called on. This applies to methods defined anywhere in the object's prototype chain (i.e. own and inherited methods). ```js const obj = { f: function() { return this; ...
code_snippets
2f3cfcc2-25fc-48fd-a321-e5ce663e9492
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/this.md
unknown
5e25958a-9e2b-4631-9642-5540160f69e2
1
SemanticChunker@1.0.0
d8ce9a5b50215f0cae389dc171fcb799bf2eaad29db4c27dae519fbd04a14279
[What is `this`?] ## What is `this`? In JavaScript, the `this` keyword refers to the object that is currently executing the code. The short version of what `this` evaluates to is as follows: - By default, `this` refers to the global object. - In a function, when not in strict mode, `this` refers to the global object...
unknown
unknown
[What is `this`?] ## What is `this`? In JavaScript, the `this` keyword refers to the object that is currently executing the code. The short version of what `this` evaluates to is as follows: - By default, `this` refers to the global object. - In a function, when not in strict mode, `this` refers to the global object...
[What is `this`?] ## What is `this`? In JavaScript, the `this` keyword refers to the object that is currently executing the code. The short version of what `this` evaluates to is as follows: - By default, `this` refers to the global object. - In a function, when not in strict mode, `this` refers to the global object...
code_snippets
2fa911de-d8f7-40d2-b045-60cd8b2ec5f2
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/this.md
unknown
5e25958a-9e2b-4631-9642-5540160f69e2
5
SemanticChunker@1.0.0
fb0eb2175938c95b55ac2140b21b4fadda0bea049c5e3497396eeeda58b568d6
[What is `this`? > Event handler context] ## Event handler context When used in an event handler, `this` refers to the element on which the listener is placed. ```js const el = document.getElementById('my-el'); el.addEventListener('click', function() { console.log(this === el); // true }); ```
unknown
unknown
[What is `this`? > Event handler context] ## Event handler context When used in an event handler, `this` refers to the element on which the listener is placed. ```js const el = document.getElementById('my-el'); el.addEventListener('click', function() { console.log(this === el); // true }); ```
[What is `this`? > Event handler context] ## Event handler context When used in an event handler, `this` refers to the element on which the listener is placed. ```js const el = document.getElementById('my-el'); el.addEventListener('click', function() { console.log(this === el); // true }); ```
code_snippets
3c8a152a-8392-4e72-8bee-fd99eb7d8479
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/this.md
unknown
5e25958a-9e2b-4631-9642-5540160f69e2
6
SemanticChunker@1.0.0
4cb1e6b9d3c791a6913c6c37a0809a87fa6d332588ed5b7d860b831eb2505293
[What is `this`? > Binding `this`] ## Binding `this` Using `Function.prototype.bind()` returns a new function from an existing one, where `this` is permanently bound to the first argument of `bind()`. ```js function f() { return this.foo; } const x = f.bind({foo: 'hello'}); console.log(x()); // 'hello' ``` Simila...
unknown
unknown
[What is `this`? > Binding `this`] ## Binding `this` Using `Function.prototype.bind()` returns a new function from an existing one, where `this` is permanently bound to the first argument of `bind()`. ```js function f() { return this.foo; } const x = f.bind({foo: 'hello'}); console.log(x()); // 'hello' ``` Simila...
[What is `this`? > Binding `this`] ## Binding `this` Using `Function.prototype.bind()` returns a new function from an existing one, where `this` is permanently bound to the first argument of `bind()`. ```js function f() { return this.foo; } const x = f.bind({foo: 'hello'}); console.log(x()); // 'hello' ``` Simila...
code_snippets
92029363-a1eb-4d6c-b3a1-bccbcd36e4fc
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/this.md
unknown
5e25958a-9e2b-4631-9642-5540160f69e2
2
SemanticChunker@1.0.0
259ba8f6e0010416070db27c86576b112dc62e139558dcf88dee5d771f173887
[What is `this`? > Function context] ## Function context When not in strict mode, a function's `this` refers to the global object. ```js function f() { return this; } console.log(f() === window); // true ``` When in strict mode, a function's `this` will be `undefined` if not set when entering the execution contex...
unknown
unknown
[What is `this`? > Function context] ## Function context When not in strict mode, a function's `this` refers to the global object. ```js function f() { return this; } console.log(f() === window); // true ``` When in strict mode, a function's `this` will be `undefined` if not set when entering the execution contex...
[What is `this`? > Function context] ## Function context When not in strict mode, a function's `this` refers to the global object. ```js function f() { return this; } console.log(f() === window); // true ``` When in strict mode, a function's `this` will be `undefined` if not set when entering the execution contex...
code_snippets
9c72c073-2cd3-401d-8a44-670f7f6920d4
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/this.md
unknown
5e25958a-9e2b-4631-9642-5540160f69e2
0
SemanticChunker@1.0.0
5983886983e16ddde1ef31b814360dcae07a03a6c3de03c785f64e4206adeb30
--- title: Understanding the "this" keyword in JavaScript shortTitle: The "this" keyword in JavaScript language: javascript tags: [function,object] cover: u-got-this excerpt: JavaScript's `this` keyword can confuse beginners and veterans alike. Learn how it works in different scenarios and start using it correctly. lis...
unknown
unknown
--- title: Understanding the "this" keyword in JavaScript shortTitle: The "this" keyword in JavaScript language: javascript tags: [function,object] cover: u-got-this excerpt: JavaScript's `this` keyword can confuse beginners and veterans alike. Learn how it works in different scenarios and start using it correctly. lis...
--- title: Understanding the "this" keyword in JavaScript shortTitle: The "this" keyword in JavaScript language: javascript tags: [function,object] cover: u-got-this excerpt: JavaScript's `this` keyword can confuse beginners and veterans alike. Learn how it works in different scenarios and start using it correctly. lis...
code_snippets
19cbdbcc-d64f-4f71-8f0c-c7a45418c72f
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/typecheck-proxy.md
unknown
119b7cec-a3d3-4310-b0af-c1e0086a9ad3
1
SemanticChunker@1.0.0
273b83cd91b06a163d9adbf22091b948c7996c2ef5754b525c1fea117aa585c5
```js const createShapeCheckerProxy = (types, shape) => { const validProps = Object.keys(shape); const handler = { set(target, prop, value) { if (!validProps.includes(prop)) return false; const validator = types[shape[prop]]; if (!validator || typeof validator !== 'function') return false; if (!validator(value))...
unknown
unknown
```js const createShapeCheckerProxy = (types, shape) => { const validProps = Object.keys(shape); const handler = { set(target, prop, value) { if (!validProps.includes(prop)) return false; const validator = types[shape[prop]]; if (!validator || typeof validator !== 'function') return false; if (!validator(value))...
```js const createShapeCheckerProxy = (types, shape) => { const validProps = Object.keys(shape); const handler = { set(target, prop, value) { if (!validProps.includes(prop)) return false; const validator = types[shape[prop]]; if (!validator || typeof validator !== 'function') return false; if (!validator(value))...
code_snippets
69c2c072-edff-425e-b23b-f7ef7bb7f56e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/typecheck-proxy.md
unknown
119b7cec-a3d3-4310-b0af-c1e0086a9ad3
0
SemanticChunker@1.0.0
6c3b4d9a8d57dc568b838162afea6d58a927daecf8796b5406a15c7a7730117b
--- title: Typechecking objects with Proxy in JavaScript shortTitle: Object type checking with Proxy language: javascript tags: [proxy,type] cover: customs excerpt: Learn how to type check objects at runtime using the powerful Proxy object in JavaScript. listed: true dateModified: 2023-04-23 --- A while back, I was wo...
unknown
unknown
--- title: Typechecking objects with Proxy in JavaScript shortTitle: Object type checking with Proxy language: javascript tags: [proxy,type] cover: customs excerpt: Learn how to type check objects at runtime using the powerful Proxy object in JavaScript. listed: true dateModified: 2023-04-23 --- A while back, I was wo...
--- title: Typechecking objects with Proxy in JavaScript shortTitle: Object type checking with Proxy language: javascript tags: [proxy,type] cover: customs excerpt: Learn how to type check objects at runtime using the powerful Proxy object in JavaScript. listed: true dateModified: 2023-04-23 --- A while back, I was wo...
code_snippets
dea1eb1e-a84b-4c95-94dd-bde6c106662b
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/typecheck-proxy.md
unknown
119b7cec-a3d3-4310-b0af-c1e0086a9ad3
2
SemanticChunker@1.0.0
c836191e0362c9d7a52efc12c73b751e24a95cbd6438c5ea26bfdb7314473f41
As you can see, `createShapeCheckerProxy` can be used with a plain object to create a reusable function that wraps an object with a type checking `Proxy`. The defined `types` are used to typecheck individual properties and could be extended to support more complex types and special rules. Overall, this can be a pretty ...
unknown
unknown
As you can see, `createShapeCheckerProxy` can be used with a plain object to create a reusable function that wraps an object with a type checking `Proxy`. The defined `types` are used to typecheck individual properties and could be extended to support more complex types and special rules. Overall, this can be a pretty ...
As you can see, `createShapeCheckerProxy` can be used with a plain object to create a reusable function that wraps an object with a type checking `Proxy`. The defined `types` are used to typecheck individual properties and could be extended to support more complex types and special rules. Overall, this can be a pretty ...
code_snippets
45656139-9552-4e64-8293-416987e27dcb
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/truthy-falsy-values.md
unknown
5f547d6b-29cb-4de5-92bb-ef83560be86c
0
SemanticChunker@1.0.0
ed34aa23ae97b088a2d99c7b757e889d0dfdcdf0b6f040abb075476f21a81eb5
--- title: What are truthy and falsy values in JavaScript? shortTitle: Truthy and falsy values language: javascript tags: [type,comparison] cover: little-bird excerpt: JavaScript uses type coercion in Boolean contexts, resulting in truthy or falsy values. Get a hang of how it all works in this quick guide. listed: true...
unknown
unknown
--- title: What are truthy and falsy values in JavaScript? shortTitle: Truthy and falsy values language: javascript tags: [type,comparison] cover: little-bird excerpt: JavaScript uses type coercion in Boolean contexts, resulting in truthy or falsy values. Get a hang of how it all works in this quick guide. listed: true...
--- title: What are truthy and falsy values in JavaScript? shortTitle: Truthy and falsy values language: javascript tags: [type,comparison] cover: little-bird excerpt: JavaScript uses type coercion in Boolean contexts, resulting in truthy or falsy values. Get a hang of how it all works in this quick guide. listed: true...
code_snippets
85bfc677-003b-48a2-8558-9dad565b0773
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-bipartite-coloring.md
unknown
4bbe7f32-45f5-44cc-b8c9-e69f54151962
2
SemanticChunker@1.0.0
4425d8e9f66668f0f76bbde6ab9a3d54eda247354405ff9de593c8f371041eb3
[Bipartite coloring > Implementation] ## Implementation To implement bipartite coloring, we can use a simple **DFS or BFS traversal algorithm**. We'll maintain a `colors` map to store the color of each node as we traverse the tree. I prefer using BFS for this task, as it allows us to color the nodes level by level. ...
unknown
unknown
[Bipartite coloring > Implementation] ## Implementation To implement bipartite coloring, we can use a simple **DFS or BFS traversal algorithm**. We'll maintain a `colors` map to store the color of each node as we traverse the tree. I prefer using BFS for this task, as it allows us to color the nodes level by level. ...
[Bipartite coloring > Implementation] ## Implementation To implement bipartite coloring, we can use a simple **DFS or BFS traversal algorithm**. We'll maintain a `colors` map to store the color of each node as we traverse the tree. I prefer using BFS for this task, as it allows us to color the nodes level by level. ...
code_snippets
96723266-2975-4085-b729-a22ab6510d1d
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-bipartite-coloring.md
unknown
4bbe7f32-45f5-44cc-b8c9-e69f54151962
1
SemanticChunker@1.0.0
7a700dd478be7997f25f4dbe7d679c4c371c59909e37b22e5f3c60af493b516d
[Bipartite coloring] ## Bipartite coloring Bipartite coloring is a way of coloring the nodes of a graph such that **no two adjacent nodes share the same color**. In the case of an undirected tree, this means that **each level of the tree can be colored with a different color**, ensuring that no two adjacent nodes (pa...
unknown
unknown
[Bipartite coloring] ## Bipartite coloring Bipartite coloring is a way of coloring the nodes of a graph such that **no two adjacent nodes share the same color**. In the case of an undirected tree, this means that **each level of the tree can be colored with a different color**, ensuring that no two adjacent nodes (pa...
[Bipartite coloring] ## Bipartite coloring Bipartite coloring is a way of coloring the nodes of a graph such that **no two adjacent nodes share the same color**. In the case of an undirected tree, this means that **each level of the tree can be colored with a different color**, ensuring that no two adjacent nodes (pa...
code_snippets
d7dcbbd5-6f9e-4088-8a68-b6ccda048407
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-bipartite-coloring.md
unknown
4bbe7f32-45f5-44cc-b8c9-e69f54151962
0
SemanticChunker@1.0.0
3579b408c4a6d5ea9cc126df5fe75ed69fa134105eaf88acfa3b6a4548107899
--- title: How can I apply bipartite coloring to an undirected tree in JavaScript? shortTitle: Undirected tree bipartite coloring language: javascript tags: [algorithm,array] cover: laptop-notes excerpt: Learn how to apply bipartite coloring to an undirected tree in JavaScript, ensuring that no two adjacent nodes share...
unknown
unknown
--- title: How can I apply bipartite coloring to an undirected tree in JavaScript? shortTitle: Undirected tree bipartite coloring language: javascript tags: [algorithm,array] cover: laptop-notes excerpt: Learn how to apply bipartite coloring to an undirected tree in JavaScript, ensuring that no two adjacent nodes share...
--- title: How can I apply bipartite coloring to an undirected tree in JavaScript? shortTitle: Undirected tree bipartite coloring language: javascript tags: [algorithm,array] cover: laptop-notes excerpt: Learn how to apply bipartite coloring to an undirected tree in JavaScript, ensuring that no two adjacent nodes share...
code_snippets
39ff1965-cb89-4102-9a50-c9ffd1b7ba0a
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undeclared-undefined-null.md
unknown
2dd812af-8b47-4df2-b9c2-dfd845161cf6
2
SemanticChunker@1.0.0
79797d87f48e4e2800f0897a105d1b44996bad7e9eb7df1c12e24af9d1a55cfd
[undeclared > undefined] ## undefined A variable is `undefined` if it hasn't been assigned a value. `undefined` is a primitive data type in JavaScript and represents the absence of a value, intentional or otherwise. ```js let x; console.log(x); // undefined ```
unknown
unknown
[undeclared > undefined] ## undefined A variable is `undefined` if it hasn't been assigned a value. `undefined` is a primitive data type in JavaScript and represents the absence of a value, intentional or otherwise. ```js let x; console.log(x); // undefined ```
[undeclared > undefined] ## undefined A variable is `undefined` if it hasn't been assigned a value. `undefined` is a primitive data type in JavaScript and represents the absence of a value, intentional or otherwise. ```js let x; console.log(x); // undefined ```
code_snippets
6526f0c2-b77a-4413-b6e9-b11ccf2ac035
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undeclared-undefined-null.md
unknown
2dd812af-8b47-4df2-b9c2-dfd845161cf6
1
SemanticChunker@1.0.0
3776a085dba6d3dbc5def7832634d3a22853756a11ccbf84876d2421405c66b7
[undeclared] ## undeclared A variable is undeclared if it has not been declared with an appropriate keyword (i.e. `var`, `let` or `const`). Accessing an undeclared variable will throw a `ReferenceError`. ```js console.log(x); // ReferenceError: x is not defined ```
unknown
unknown
[undeclared] ## undeclared A variable is undeclared if it has not been declared with an appropriate keyword (i.e. `var`, `let` or `const`). Accessing an undeclared variable will throw a `ReferenceError`. ```js console.log(x); // ReferenceError: x is not defined ```
[undeclared] ## undeclared A variable is undeclared if it has not been declared with an appropriate keyword (i.e. `var`, `let` or `const`). Accessing an undeclared variable will throw a `ReferenceError`. ```js console.log(x); // ReferenceError: x is not defined ```
code_snippets
858167d2-f4be-482f-acba-8d15cfd3c557
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undeclared-undefined-null.md
unknown
2dd812af-8b47-4df2-b9c2-dfd845161cf6
4
SemanticChunker@1.0.0
306bf6d73844f26507d0e1c5827c7595239d8e2ef376e92459e9790182129fbf
[undeclared > Checking for empty states] ## Checking for empty states Undeclared variables will throw an error, which makes them easy to spot and are not very common anyways. `undefined` and `null` can be easily spotted with a conditional as they are both falsy values. Due to that, `null` and `undefined` are loosely ...
unknown
unknown
[undeclared > Checking for empty states] ## Checking for empty states Undeclared variables will throw an error, which makes them easy to spot and are not very common anyways. `undefined` and `null` can be easily spotted with a conditional as they are both falsy values. Due to that, `null` and `undefined` are loosely ...
[undeclared > Checking for empty states] ## Checking for empty states Undeclared variables will throw an error, which makes them easy to spot and are not very common anyways. `undefined` and `null` can be easily spotted with a conditional as they are both falsy values. Due to that, `null` and `undefined` are loosely ...
code_snippets
bc2216b8-0610-430e-be5e-9379ac8448c8
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undeclared-undefined-null.md
unknown
2dd812af-8b47-4df2-b9c2-dfd845161cf6
0
SemanticChunker@1.0.0
a0087e34286f5fb9614b796cd59633dc07bb2dc7299c51d89aeb98d470cb2944
--- title: What's the difference between undeclared, undefined and null in JavaScript? shortTitle: Undeclared, undefined and null language: javascript tags: [type] cover: river-houses excerpt: JavaScript has three different empty states for variables. Learn their differences and how you can check for each one. listed: ...
unknown
unknown
--- title: What's the difference between undeclared, undefined and null in JavaScript? shortTitle: Undeclared, undefined and null language: javascript tags: [type] cover: river-houses excerpt: JavaScript has three different empty states for variables. Learn their differences and how you can check for each one. listed: ...
--- title: What's the difference between undeclared, undefined and null in JavaScript? shortTitle: Undeclared, undefined and null language: javascript tags: [type] cover: river-houses excerpt: JavaScript has three different empty states for variables. Learn their differences and how you can check for each one. listed: ...
code_snippets
d22d6680-61f1-48d9-8c54-2f3e424fc0d1
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undeclared-undefined-null.md
unknown
2dd812af-8b47-4df2-b9c2-dfd845161cf6
3
SemanticChunker@1.0.0
3050e0ff4e6bc3828fc84783c4f38db33d7f24f28bba1bf2172facb2638f2719
[undeclared > null] ## null A variable is assigned a value of `null` like any other value. `null` is also primitive data type in JavaScript and always represents the intentional absence of a value. ```js let x = null; console.log(x); // null ```
unknown
unknown
[undeclared > null] ## null A variable is assigned a value of `null` like any other value. `null` is also primitive data type in JavaScript and always represents the intentional absence of a value. ```js let x = null; console.log(x); // null ```
[undeclared > null] ## null A variable is assigned a value of `null` like any other value. `null` is also primitive data type in JavaScript and always represents the intentional absence of a value. ```js let x = null; console.log(x); // null ```
code_snippets
165ed050-0136-48a5-8136-3d87af1a626b
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/typecheck-nodejs-streams.md
unknown
7d46f59b-4005-448d-97ed-0aa6253eb225
1
SemanticChunker@1.0.0
ab6ba43e83481e69051d512abc8ef139b346d2afbf858d22c8662c675b09fc15
[Check if value is a stream] ## Check if value is a stream In the most general case, we can check if a value is a stream by checking if it is an **object** and has a `pipe` property that is a function. ```js import { createReadStream } from 'fs'; const isStream = val => val !== null && typeof val === 'object' && t...
unknown
unknown
[Check if value is a stream] ## Check if value is a stream In the most general case, we can check if a value is a stream by checking if it is an **object** and has a `pipe` property that is a function. ```js import { createReadStream } from 'fs'; const isStream = val => val !== null && typeof val === 'object' && t...
[Check if value is a stream] ## Check if value is a stream In the most general case, we can check if a value is a stream by checking if it is an **object** and has a `pipe` property that is a function. ```js import { createReadStream } from 'fs'; const isStream = val => val !== null && typeof val === 'object' && t...
code_snippets
17c62b0f-7c69-4398-95c6-8092d084fe3c
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/typecheck-nodejs-streams.md
unknown
7d46f59b-4005-448d-97ed-0aa6253eb225
2
SemanticChunker@1.0.0
527a83e752e3eb701acbc02ce5aadd22c762d8a8b87519e9ee1b792bd50081d5
[Check if value is a stream > Check if value is a readable stream] ## Check if value is a readable stream A [readable stream](https://nodejs.org/api/stream.html#readable-streams) needs to have a `_read` function and a `_readableState` object. This is in addition to the general stream check, defined previously. ```js...
unknown
unknown
[Check if value is a stream > Check if value is a readable stream] ## Check if value is a readable stream A [readable stream](https://nodejs.org/api/stream.html#readable-streams) needs to have a `_read` function and a `_readableState` object. This is in addition to the general stream check, defined previously. ```js...
[Check if value is a stream > Check if value is a readable stream] ## Check if value is a readable stream A [readable stream](https://nodejs.org/api/stream.html#readable-streams) needs to have a `_read` function and a `_readableState` object. This is in addition to the general stream check, defined previously. ```js...
code_snippets
6a3b3e8a-57f2-43f4-bf73-f57a2bbcae3a
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/typecheck-nodejs-streams.md
unknown
7d46f59b-4005-448d-97ed-0aa6253eb225
3
SemanticChunker@1.0.0
064321f6fdf5db2b60066bf96863c29ef029ed02470c4f8e920f9345348a635a
[Check if value is a stream > Check if value is a writable stream] ## Check if value is a writable stream A [writable stream](https://nodejs.org/api/stream.html#writable-streams) needs to have a `_write` function and a `_writableState` object. This is in addition to the general stream check, defined previously. ```j...
unknown
unknown
[Check if value is a stream > Check if value is a writable stream] ## Check if value is a writable stream A [writable stream](https://nodejs.org/api/stream.html#writable-streams) needs to have a `_write` function and a `_writableState` object. This is in addition to the general stream check, defined previously. ```j...
[Check if value is a stream > Check if value is a writable stream] ## Check if value is a writable stream A [writable stream](https://nodejs.org/api/stream.html#writable-streams) needs to have a `_write` function and a `_writableState` object. This is in addition to the general stream check, defined previously. ```j...
code_snippets
d30e1e11-169d-42e8-b993-a4f924cf8eca
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/typecheck-nodejs-streams.md
unknown
7d46f59b-4005-448d-97ed-0aa6253eb225
4
SemanticChunker@1.0.0
8e82bc2d967404467a9a5a3990c7cb744e8641c7180ef6607f3e8481a33e329a
[Check if value is a stream > Check if value is a duplex stream] ## Check if value is a duplex stream Finally, a [duplex stream](https://nodejs.org/api/stream.html#class-streamduplex) needs to match the conditions for both a readable and a writable stream, as defined previously. ```js import Stream from 'stream'; c...
unknown
unknown
[Check if value is a stream > Check if value is a duplex stream] ## Check if value is a duplex stream Finally, a [duplex stream](https://nodejs.org/api/stream.html#class-streamduplex) needs to match the conditions for both a readable and a writable stream, as defined previously. ```js import Stream from 'stream'; c...
[Check if value is a stream > Check if value is a duplex stream] ## Check if value is a duplex stream Finally, a [duplex stream](https://nodejs.org/api/stream.html#class-streamduplex) needs to match the conditions for both a readable and a writable stream, as defined previously. ```js import Stream from 'stream'; c...
code_snippets
e174f994-4c57-4694-b263-8e0761c48336
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/typecheck-nodejs-streams.md
unknown
7d46f59b-4005-448d-97ed-0aa6253eb225
0
SemanticChunker@1.0.0
9570b8a536bb18e58417473d3968b7a7e3d381d00967369d8cd37bc29df6e225
--- title: How can I check if a value implements a stream in Node.js? shortTitle: Stream type checking language: javascript tags: [node,type] excerpt: Learn how to type check for different types of streams in Node.js. cover: mountain-lake-cottage-2 listed: true dateModified: 2023-12-21 --- A [Stream](https://nodejs.or...
unknown
unknown
--- title: How can I check if a value implements a stream in Node.js? shortTitle: Stream type checking language: javascript tags: [node,type] excerpt: Learn how to type check for different types of streams in Node.js. cover: mountain-lake-cottage-2 listed: true dateModified: 2023-12-21 --- A [Stream](https://nodejs.or...
--- title: How can I check if a value implements a stream in Node.js? shortTitle: Stream type checking language: javascript tags: [node,type] excerpt: Learn how to type check for different types of streams in Node.js. cover: mountain-lake-cottage-2 listed: true dateModified: 2023-12-21 --- A [Stream](https://nodejs.or...
code_snippets
0df2695a-782b-4bac-836d-61834e372374
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/typecheck-array.md
unknown
bf8c29ce-c4a5-4011-a17e-22d255d5c55e
0
SemanticChunker@1.0.0
1b2a78fd3775e61dc0fe6af14344719efbccf465c0cda9d77bd52f3f51982cd2
--- title: Typechecking JavaScript arrays with Array.isArray() shortTitle: Array typechecking language: javascript tags: [type,array] cover: purple-flower-field excerpt: Make sure to use the correct method when checking if a JavaScript object is an array. listed: true dateModified: 2022-11-06 --- To determine if an ob...
unknown
unknown
--- title: Typechecking JavaScript arrays with Array.isArray() shortTitle: Array typechecking language: javascript tags: [type,array] cover: purple-flower-field excerpt: Make sure to use the correct method when checking if a JavaScript object is an array. listed: true dateModified: 2022-11-06 --- To determine if an ob...
--- title: Typechecking JavaScript arrays with Array.isArray() shortTitle: Array typechecking language: javascript tags: [type,array] cover: purple-flower-field excerpt: Make sure to use the correct method when checking if a JavaScript object is an array. listed: true dateModified: 2022-11-06 --- To determine if an ob...
code_snippets
48efe7cd-c986-4906-b255-bee4aceb57a0
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/trigger-event.md
unknown
6d597cd5-44ca-42a7-9f10-17601adb52f0
0
SemanticChunker@1.0.0
892e9ed653cd6dc84a1dbaae66b86d68a34f872a4ceffc9dac5b6d2ecef02ec7
--- title: Programmatically trigger event on HTML element using JavaScript shortTitle: Trigger event on HTML element language: javascript tags: [browser,event] cover: cloudy-mountaintop-2 excerpt: Learn how to trigger an event on an HTML element using JavaScript. listed: true dateModified: 2023-11-03 --- JavaScript's ...
unknown
unknown
--- title: Programmatically trigger event on HTML element using JavaScript shortTitle: Trigger event on HTML element language: javascript tags: [browser,event] cover: cloudy-mountaintop-2 excerpt: Learn how to trigger an event on an HTML element using JavaScript. listed: true dateModified: 2023-11-03 --- JavaScript's ...
--- title: Programmatically trigger event on HTML element using JavaScript shortTitle: Trigger event on HTML element language: javascript tags: [browser,event] cover: cloudy-mountaintop-2 excerpt: Learn how to trigger an event on an HTML element using JavaScript. listed: true dateModified: 2023-11-03 --- JavaScript's ...
code_snippets
05c0bd8d-c873-4a05-a193-2086774b315c
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-degree-min-height-tree.md
unknown
bfa04919-3f29-4ee4-89c6-0ac9723efe73
0
SemanticChunker@1.0.0
db2bb8884e5d3b3cff90a0406bb91f5141f8f2a94fac306ffd6b5570dcc605eb
--- title: How can I find the minimum height tree in an undirected tree in JavaScript? shortTitle: Minimum height undirected tree language: javascript tags: [algorithm,array] cover: cozy-cafe excerpt: Using the degree of nodes, we can employ a very efficient algorithmic trick to find the minimum height tree in an undir...
unknown
unknown
--- title: How can I find the minimum height tree in an undirected tree in JavaScript? shortTitle: Minimum height undirected tree language: javascript tags: [algorithm,array] cover: cozy-cafe excerpt: Using the degree of nodes, we can employ a very efficient algorithmic trick to find the minimum height tree in an undir...
--- title: How can I find the minimum height tree in an undirected tree in JavaScript? shortTitle: Minimum height undirected tree language: javascript tags: [algorithm,array] cover: cozy-cafe excerpt: Using the degree of nodes, we can employ a very efficient algorithmic trick to find the minimum height tree in an undir...
code_snippets
193fff41-d068-41c2-be7f-e830898b53a0
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-degree-min-height-tree.md
unknown
bfa04919-3f29-4ee4-89c6-0ac9723efe73
2
SemanticChunker@1.0.0
86f1ff7e51a5fbb2b0e76b4469123790d7260d76575d5cf811da057a267523a8
[Node degrees > Minimum height tree] ## Minimum height tree Given a tree, the **minimum height tree** is defined as the tree that has the **minimum number of edges from the root to any leaf node**. In other words, it is the tree that minimizes the height of the tree. For our example, this would be a tree with a heig...
unknown
unknown
[Node degrees > Minimum height tree] ## Minimum height tree Given a tree, the **minimum height tree** is defined as the tree that has the **minimum number of edges from the root to any leaf node**. In other words, it is the tree that minimizes the height of the tree. For our example, this would be a tree with a heig...
[Node degrees > Minimum height tree] ## Minimum height tree Given a tree, the **minimum height tree** is defined as the tree that has the **minimum number of edges from the root to any leaf node**. In other words, it is the tree that minimizes the height of the tree. For our example, this would be a tree with a heig...
code_snippets
34b19b02-bc74-457f-9ef0-f2e77f1c7d38
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-degree-min-height-tree.md
unknown
bfa04919-3f29-4ee4-89c6-0ac9723efe73
3
SemanticChunker@1.0.0
791e39053046ac8383cede4d0ca0147fa3f9a525b3bb284252e7236fbf8fdab2
[Node degrees > Implementation] ## Implementation The key insight to this problem comes from the fact that **the minimum height tree can be found by removing leaf nodes iteratively**. A leaf node is defined as a node with a degree of `1` (i.e., it has only one edge connected to it). Using this insight, we can effici...
unknown
unknown
[Node degrees > Implementation] ## Implementation The key insight to this problem comes from the fact that **the minimum height tree can be found by removing leaf nodes iteratively**. A leaf node is defined as a node with a degree of `1` (i.e., it has only one edge connected to it). Using this insight, we can effici...
[Node degrees > Implementation] ## Implementation The key insight to this problem comes from the fact that **the minimum height tree can be found by removing leaf nodes iteratively**. A leaf node is defined as a node with a degree of `1` (i.e., it has only one edge connected to it). Using this insight, we can effici...
code_snippets
58d9d2a6-4427-4d8c-9d83-30fc8cc9e07d
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-degree-min-height-tree.md
unknown
bfa04919-3f29-4ee4-89c6-0ac9723efe73
4
SemanticChunker@1.0.0
00c0a76a66404a723703ddbf2d5f59ae73d3b5b8610c53605b2749e848e4b1b5
[Node degrees > Conclusion] ## Conclusion While minimum height trees may seem intimidating at first, they're actually quite a straightforward problem to solve using the concept of node degrees and iterative leaf removal. By understanding the properties of the data structure, we can unlock efficient and elegant soluti...
unknown
unknown
[Node degrees > Conclusion] ## Conclusion While minimum height trees may seem intimidating at first, they're actually quite a straightforward problem to solve using the concept of node degrees and iterative leaf removal. By understanding the properties of the data structure, we can unlock efficient and elegant soluti...
[Node degrees > Conclusion] ## Conclusion While minimum height trees may seem intimidating at first, they're actually quite a straightforward problem to solve using the concept of node degrees and iterative leaf removal. By understanding the properties of the data structure, we can unlock efficient and elegant soluti...
code_snippets
91eacb60-cbdd-41f1-add7-752079aa3171
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-degree-min-height-tree.md
unknown
bfa04919-3f29-4ee4-89c6-0ac9723efe73
1
SemanticChunker@1.0.0
af9793f5a15dcb0abb5c747df799f23f78c4ba67182df01cd57235ee8527d3aa
[Node degrees] ## Node degrees The degree of a node in an undirected tree is the number of edges connected to it. Note that, as the tree is undirected, there is no indegree or outdegree; the degree is simply the count of edges connected to that node. Let's look at the by now familiar undirected tree example: ![Undi...
unknown
unknown
[Node degrees] ## Node degrees The degree of a node in an undirected tree is the number of edges connected to it. Note that, as the tree is undirected, there is no indegree or outdegree; the degree is simply the count of edges connected to that node. Let's look at the by now familiar undirected tree example: ![Undi...
[Node degrees] ## Node degrees The degree of a node in an undirected tree is the number of edges connected to it. Note that, as the tree is undirected, there is no indegree or outdegree; the degree is simply the count of edges connected to that node. Let's look at the by now familiar undirected tree example: ![Undi...
code_snippets
9e96966b-e584-4dec-9a64-4e4e143180b5
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/transpose-matrix.md
unknown
8cadc44b-7399-48e9-a0dd-0fb07add1a40
0
SemanticChunker@1.0.0
a1cff827b759ebb67d5063409f5aa2d5513d36ebf76e04ae8e0e23aad1601f71
--- title: Transpose a matrix in JavaScript shortTitle: Transpose matrix language: javascript tags: [array] cover: camera-zoom excerpt: Learn how to transpose a two-dimensional array in JavaScript. listed: true dateModified: 2024-07-18 --- A **matrix transpose** is an operation that switches the rows and columns of a ...
unknown
unknown
--- title: Transpose a matrix in JavaScript shortTitle: Transpose matrix language: javascript tags: [array] cover: camera-zoom excerpt: Learn how to transpose a two-dimensional array in JavaScript. listed: true dateModified: 2024-07-18 --- A **matrix transpose** is an operation that switches the rows and columns of a ...
--- title: Transpose a matrix in JavaScript shortTitle: Transpose matrix language: javascript tags: [array] cover: camera-zoom excerpt: Learn how to transpose a two-dimensional array in JavaScript. listed: true dateModified: 2024-07-18 --- A **matrix transpose** is an operation that switches the rows and columns of a ...
code_snippets
30ef1a72-10c1-44df-b698-227a0b788055
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/truncate-string.md
unknown
b6db3178-997a-4991-831d-80bc78356719
2
SemanticChunker@1.0.0
118d9b90df835983e3505017e359bdb9b0d3efd73af95f3e0d5707d79dbd9a0f
[Truncate string > Truncate string, adding ellipsis] ## Truncate string, adding ellipsis That works, but the result doesn't hint at the fact that the string has been truncated. Let's **add an ellipsis** to the end of the string to indicate that it has been truncated. We can do this by appending `'...'` to the end of ...
unknown
unknown
[Truncate string > Truncate string, adding ellipsis] ## Truncate string, adding ellipsis That works, but the result doesn't hint at the fact that the string has been truncated. Let's **add an ellipsis** to the end of the string to indicate that it has been truncated. We can do this by appending `'...'` to the end of ...
[Truncate string > Truncate string, adding ellipsis] ## Truncate string, adding ellipsis That works, but the result doesn't hint at the fact that the string has been truncated. Let's **add an ellipsis** to the end of the string to indicate that it has been truncated. We can do this by appending `'...'` to the end of ...
code_snippets
9bf87f9c-7fa1-4767-b3a9-9c32970f73b2
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/truncate-string.md
unknown
b6db3178-997a-4991-831d-80bc78356719
5
SemanticChunker@1.0.0
cd70fab7c29274c9a051d93a82d63b11178036a1a50a2c6e299b7dfc9cec05b8
[Truncate string > Locale-sensitive string truncation] > [!NOTE] > > The `Intl.Segmenter` object is available in modern browsers and Node.js, since **v16.0.0**. Make sure to check compatibility for your target environment.
unknown
unknown
[Truncate string > Locale-sensitive string truncation] > [!NOTE] > > The `Intl.Segmenter` object is available in modern browsers and Node.js, since **v16.0.0**. Make sure to check compatibility for your target environment.
[Truncate string > Locale-sensitive string truncation] > [!NOTE] > > The `Intl.Segmenter` object is available in modern browsers and Node.js, since **v16.0.0**. Make sure to check compatibility for your target environment.
code_snippets
9d4937e2-56b9-4506-8de2-b0a644cc944f
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/truncate-string.md
unknown
b6db3178-997a-4991-831d-80bc78356719
0
SemanticChunker@1.0.0
fd1be4461b95bd51ca68a7ed9bff9f0e61c02ba76701bb240d8c6d8e4f0737b1
--- title: How can I truncate a string to a specified length using JavaScript? shortTitle: Truncate string language: javascript tags: [string] cover: reflection-on-lake excerpt: String splitting and truncation, both simple and locale-sensitive are possible in JavaScript. Learn how in this guide. listed: true dateModifi...
unknown
unknown
--- title: How can I truncate a string to a specified length using JavaScript? shortTitle: Truncate string language: javascript tags: [string] cover: reflection-on-lake excerpt: String splitting and truncation, both simple and locale-sensitive are possible in JavaScript. Learn how in this guide. listed: true dateModifi...
--- title: How can I truncate a string to a specified length using JavaScript? shortTitle: Truncate string language: javascript tags: [string] cover: reflection-on-lake excerpt: String splitting and truncation, both simple and locale-sensitive are possible in JavaScript. Learn how in this guide. listed: true dateModifi...
code_snippets
b4b7c7f4-be39-4a5b-ba39-adf3ee3eb8df
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/truncate-string.md
unknown
b6db3178-997a-4991-831d-80bc78356719
4
SemanticChunker@1.0.0
6957df888021f3c851767a10ca4d5c3fd0d1a3cf9dc6df1a5c6d488d6b5f403a
[Truncate string > Locale-sensitive string truncation] ## Locale-sensitive string truncation Finally, we've arrived at the most complex problem - **locale-sensitive string truncation**. This is a difficult problem to solve, which is why JavaScript has kindly added the `Intl.Segmenter` object. `Intl.Segmenter` allows...
unknown
unknown
[Truncate string > Locale-sensitive string truncation] ## Locale-sensitive string truncation Finally, we've arrived at the most complex problem - **locale-sensitive string truncation**. This is a difficult problem to solve, which is why JavaScript has kindly added the `Intl.Segmenter` object. `Intl.Segmenter` allows...
[Truncate string > Locale-sensitive string truncation] ## Locale-sensitive string truncation Finally, we've arrived at the most complex problem - **locale-sensitive string truncation**. This is a difficult problem to solve, which is why JavaScript has kindly added the `Intl.Segmenter` object. `Intl.Segmenter` allows...
code_snippets
e273cb77-96b9-497d-bf06-104339512d4e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/truncate-string.md
unknown
b6db3178-997a-4991-831d-80bc78356719
1
SemanticChunker@1.0.0
facd4f37b605deb9bc3591456319d02e2277c5ded7999c305175b802977c6c44
[Truncate string] ## Truncate string The absolute simplest way to truncate a string is to use `String.prototype.slice()`. All you have to do is compare `String.prototype.length` to the desired length and return the string truncated to the desired length. If the string is **shorter than the desired length**, return th...
unknown
unknown
[Truncate string] ## Truncate string The absolute simplest way to truncate a string is to use `String.prototype.slice()`. All you have to do is compare `String.prototype.length` to the desired length and return the string truncated to the desired length. If the string is **shorter than the desired length**, return th...
[Truncate string] ## Truncate string The absolute simplest way to truncate a string is to use `String.prototype.slice()`. All you have to do is compare `String.prototype.length` to the desired length and return the string truncated to the desired length. If the string is **shorter than the desired length**, return th...
code_snippets
e74f1a37-168e-4130-9845-c9c44f56f859
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/truncate-string.md
unknown
b6db3178-997a-4991-831d-80bc78356719
3
SemanticChunker@1.0.0
6d48e35efc0809ad61192ef2459fd81b8bf02cb702234e8762b24d481371608f
[Truncate string > Truncate string at whitespace] ## Truncate string at whitespace Up until this point, we've been truncating the string at the specified length, regardless of whether it's in the middle of a word or not. But you might need to **respect word boundaries** and truncate the string at a whitespace charact...
unknown
unknown
[Truncate string > Truncate string at whitespace] ## Truncate string at whitespace Up until this point, we've been truncating the string at the specified length, regardless of whether it's in the middle of a word or not. But you might need to **respect word boundaries** and truncate the string at a whitespace charact...
[Truncate string > Truncate string at whitespace] ## Truncate string at whitespace Up until this point, we've been truncating the string at the specified length, regardless of whether it's in the middle of a word or not. But you might need to **respect word boundaries** and truncate the string at a whitespace charact...
code_snippets
0e8ddfad-0951-4115-a083-f520267807be
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
12
SemanticChunker@1.0.0
a4ced5e1467ce3ac56ded73b60e0f1f21290acd48427f8d1531dab43789971b4
[API design > Edge cases] ### Edge cases Even with all of these systems in place, there will most likely be **special cases** that don't fit the mold. We'll address these on a case-by-case basis, but having established a **general strategy** will help us make educated decisions that will make sense for users.
unknown
unknown
[API design > Edge cases] ### Edge cases Even with all of these systems in place, there will most likely be **special cases** that don't fit the mold. We'll address these on a case-by-case basis, but having established a **general strategy** will help us make educated decisions that will make sense for users.
[API design > Edge cases] ### Edge cases Even with all of these systems in place, there will most likely be **special cases** that don't fit the mold. We'll address these on a case-by-case basis, but having established a **general strategy** will help us make educated decisions that will make sense for users.
code_snippets
1749ef78-b7ed-40a4-9135-b5067cb35f17
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
15
SemanticChunker@1.0.0
229619eff2676e6680e4a0ce9404c2a8741493ae074df52abcbf18b3769d9ddb
[Edge cases > Character sets] #### Character sets Last but not last, character sets are a special case in and of themselves. A range has a start and an end, but what happens if we want to match any character in a set of characters that do not form a contiguous range? ```js // Good - simple range range('a', 'z'); // ...
unknown
unknown
[Edge cases > Character sets] #### Character sets Last but not last, character sets are a special case in and of themselves. A range has a start and an end, but what happens if we want to match any character in a set of characters that do not form a contiguous range? ```js // Good - simple range range('a', 'z'); // ...
[Edge cases > Character sets] #### Character sets Last but not last, character sets are a special case in and of themselves. A range has a start and an end, but what happens if we want to match any character in a set of characters that do not form a contiguous range? ```js // Good - simple range range('a', 'z'); // ...
code_snippets
252acea0-8102-4574-b050-5f2da29d8da9
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
14
SemanticChunker@1.0.0
8d21162d2170f47351e715bc3e0f93c8ea216f56d081aa2e42463683191cf8ca
[Edge cases > Quantifiers] #### Quantifiers The `repeat` quantifier is the most common one in these examples and for good reason. It's a very common pattern that's also quite versatile. However, designing it in a way that makes sense is a bit tricky. We need to support three resulting syntaxes: 1. Exact match (exact...
unknown
unknown
[Edge cases > Quantifiers] #### Quantifiers The `repeat` quantifier is the most common one in these examples and for good reason. It's a very common pattern that's also quite versatile. However, designing it in a way that makes sense is a bit tricky. We need to support three resulting syntaxes: 1. Exact match (exact...
[Edge cases > Quantifiers] #### Quantifiers The `repeat` quantifier is the most common one in these examples and for good reason. It's a very common pattern that's also quite versatile. However, designing it in a way that makes sense is a bit tricky. We need to support three resulting syntaxes: 1. Exact match (exact...
code_snippets
36b9e6b0-9aea-422f-8c96-db011a262702
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
7
SemanticChunker@1.0.0
0f694a56c6658cc156330d8f3dde82e827433c1ac22db40083ff9e3de376d556
[Problem brief > API design] ## API design Having established the goals and the general direction, it's time to look closer upon the developer experience. The drafts I made with TDD so far, even if not fully functional, gave me a good idea of what the API should look like. They also made me aware of **potential issue...
unknown
unknown
[Problem brief > API design] ## API design Having established the goals and the general direction, it's time to look closer upon the developer experience. The drafts I made with TDD so far, even if not fully functional, gave me a good idea of what the API should look like. They also made me aware of **potential issue...
[Problem brief > API design] ## API design Having established the goals and the general direction, it's time to look closer upon the developer experience. The drafts I made with TDD so far, even if not fully functional, gave me a good idea of what the API should look like. They also made me aware of **potential issue...
code_snippets
3783a20e-080f-4474-9457-a67247fd5523
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
4
SemanticChunker@1.0.0
2b413a723f7bb4a5393ba600c1f3acac173d7de0579626b8ebb0f9e7c4da6b26
[Goal statement > Reusability] ### Reusability The less ambitious goal for this project is to make it easier to **reuse RegExp patterns**. This means that I should be able to create a pattern once and use it in multiple places. This boils down to creating all the necessary **building blocks** to make this possible an...
unknown
unknown
[Goal statement > Reusability] ### Reusability The less ambitious goal for this project is to make it easier to **reuse RegExp patterns**. This means that I should be able to create a pattern once and use it in multiple places. This boils down to creating all the necessary **building blocks** to make this possible an...
[Goal statement > Reusability] ### Reusability The less ambitious goal for this project is to make it easier to **reuse RegExp patterns**. This means that I should be able to create a pattern once and use it in multiple places. This boils down to creating all the necessary **building blocks** to make this possible an...
code_snippets
47e1b8c5-b0f8-4ee3-9fb4-453f8a379047
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
0
SemanticChunker@1.0.0
e4602a471139a39b2de286f1602c61898047faeff581d0cef0db85d641e2d48a
--- title: Designing a user-centric API for a JavaScript library shortTitle: User-centric API design language: javascript tags: [webdev,regexp] cover: succulent-6 excerpt: Building atop the TDD foundation from last time, let's explore how to design a user-centric API for our JavaScript library. listed: true dateModifie...
unknown
unknown
--- title: Designing a user-centric API for a JavaScript library shortTitle: User-centric API design language: javascript tags: [webdev,regexp] cover: succulent-6 excerpt: Building atop the TDD foundation from last time, let's explore how to design a user-centric API for our JavaScript library. listed: true dateModifie...
--- title: Designing a user-centric API for a JavaScript library shortTitle: User-centric API design language: javascript tags: [webdev,regexp] cover: succulent-6 excerpt: Building atop the TDD foundation from last time, let's explore how to design a user-centric API for our JavaScript library. listed: true dateModifie...
code_snippets
54749e81-2d94-4024-ab8a-8288bbcc715e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
6
SemanticChunker@1.0.0
44f1064a1889dd5986c8f96654bc2783d8822314e2fd900acb11fe12caf1c340
[Goal statement > Readability & maintainability] ``` ```js title="src/myDraft.js" // Pseudocode approximation of what I imagine under the hood const or = (...patterns) => `(${patterns.join('|')})`; const concat = (...patterns) => patterns.join(''); const zeroOrMore = pattern => `${pattern}*`; const zeroOrOne = patter...
unknown
unknown
[Goal statement > Readability & maintainability] ``` ```js title="src/myDraft.js" // Pseudocode approximation of what I imagine under the hood const or = (...patterns) => `(${patterns.join('|')})`; const concat = (...patterns) => patterns.join(''); const zeroOrMore = pattern => `${pattern}*`; const zeroOrOne = patter...
[Goal statement > Readability & maintainability] ``` ```js title="src/myDraft.js" // Pseudocode approximation of what I imagine under the hood const or = (...patterns) => `(${patterns.join('|')})`; const concat = (...patterns) => patterns.join(''); const zeroOrMore = pattern => `${pattern}*`; const zeroOrOne = patter...
code_snippets
67c142cc-5a3c-452d-b17d-9f5383eb5113
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
5
SemanticChunker@1.0.0
fcb264b26f6f6f0ec9dd5a1048ad0e0b02eea327bfcc12d2c4d9f05bd98e54c1
[Goal statement > Readability & maintainability] ### Readability & maintainability Our **health metrics**, if you will, are how easy it is to read and maintain the code written with this library. The main hassle of RegExp is how much time is wasted trying to understand what the last person - or you from the past - di...
unknown
unknown
[Goal statement > Readability & maintainability] ### Readability & maintainability Our **health metrics**, if you will, are how easy it is to read and maintain the code written with this library. The main hassle of RegExp is how much time is wasted trying to understand what the last person - or you from the past - di...
[Goal statement > Readability & maintainability] ### Readability & maintainability Our **health metrics**, if you will, are how easy it is to read and maintain the code written with this library. The main hassle of RegExp is how much time is wasted trying to understand what the last person - or you from the past - di...
code_snippets
6df0c004-be7b-49fe-9d51-ad8bdb6167c1
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
1
SemanticChunker@1.0.0
ed460e105273bf9966430f2992ea352b4d167e529c3c672f54a65a9f80465a80
[Problem brief] ## Problem brief My project involves around a simple concept - the **regular expression** <dfn title="A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across doma...
unknown
unknown
[Problem brief] ## Problem brief My project involves around a simple concept - the **regular expression** <dfn title="A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across doma...
[Problem brief] ## Problem brief My project involves around a simple concept - the **regular expression** <dfn title="A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across doma...
code_snippets
74a377fe-a179-49b2-a9b5-5aca7d2dbc61
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
10
SemanticChunker@1.0.0
1101185f7ea6f5c2d97b65038c6896f5468b701f10b2bfedaab15dfb430f46f5
[API design > Special arguments] ### Special arguments Naturally, there will be edge cases to any design, no matter how nice and elegant it is. In the case of this little library, some patterns, like `namedGroup` or `repeat`, will require some special arguments. While initially I thought we can stick those arguments...
unknown
unknown
[API design > Special arguments] ### Special arguments Naturally, there will be edge cases to any design, no matter how nice and elegant it is. In the case of this little library, some patterns, like `namedGroup` or `repeat`, will require some special arguments. While initially I thought we can stick those arguments...
[API design > Special arguments] ### Special arguments Naturally, there will be edge cases to any design, no matter how nice and elegant it is. In the case of this little library, some patterns, like `namedGroup` or `repeat`, will require some special arguments. While initially I thought we can stick those arguments...
code_snippets
7e9e1f12-5d35-49cf-8c96-e1f283495a78
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
11
SemanticChunker@1.0.0
36539a8c887b3f9b620fb34a411190c783e46109fc451628b4d3d89efe5f8f72
[API design > Named arguments] ### Named arguments One of the features I wish JavaScript had is something like [Ruby's keyword arguments](https://thoughtbot.com/upcase/videos/ruby-keyword-arguments). Luckily, for many years now, we've been using objects and, as early as ES6 was around, [object destructuring](https://...
unknown
unknown
[API design > Named arguments] ### Named arguments One of the features I wish JavaScript had is something like [Ruby's keyword arguments](https://thoughtbot.com/upcase/videos/ruby-keyword-arguments). Luckily, for many years now, we've been using objects and, as early as ES6 was around, [object destructuring](https://...
[API design > Named arguments] ### Named arguments One of the features I wish JavaScript had is something like [Ruby's keyword arguments](https://thoughtbot.com/upcase/videos/ruby-keyword-arguments). Luckily, for many years now, we've been using objects and, as early as ES6 was around, [object destructuring](https://...
code_snippets
82396af3-52e0-4c68-a37a-f2e654bb1320
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
16
SemanticChunker@1.0.0
e4d4faefcf3c77ca1b8918893cd2298077ee60c9031d6c4d48c08211f4f6c0b6
[Problem brief > Conclusion] ## Conclusion That was quite a long journey, but I believe careful, **user-centric API design** is crucial to the success of any library or tool. A well-designed API can make a library a joy to use, while a poorly designed one can make it a nightmare. After all, developer experience is no...
unknown
unknown
[Problem brief > Conclusion] ## Conclusion That was quite a long journey, but I believe careful, **user-centric API design** is crucial to the success of any library or tool. A well-designed API can make a library a joy to use, while a poorly designed one can make it a nightmare. After all, developer experience is no...
[Problem brief > Conclusion] ## Conclusion That was quite a long journey, but I believe careful, **user-centric API design** is crucial to the success of any library or tool. A well-designed API can make a library a joy to use, while a poorly designed one can make it a nightmare. After all, developer experience is no...
code_snippets
8e9d39a1-7534-4038-94c8-cb127c206431
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
2
SemanticChunker@1.0.0
25358f4cda9ee94ab3049c4e48651005e962af35680ceca1b63ce94dee9d601d
[Problem brief > Goal statement] ## Goal statement My primary goal is to create a more **natural way to express regular expressions**. As a secondary goal, I also want to make it easier to **reuse patterns**, so that one could conceptually create building blocks or libraries of RegExp patterns. Finally, as with anyth...
unknown
unknown
[Problem brief > Goal statement] ## Goal statement My primary goal is to create a more **natural way to express regular expressions**. As a secondary goal, I also want to make it easier to **reuse patterns**, so that one could conceptually create building blocks or libraries of RegExp patterns. Finally, as with anyth...
[Problem brief > Goal statement] ## Goal statement My primary goal is to create a more **natural way to express regular expressions**. As a secondary goal, I also want to make it easier to **reuse patterns**, so that one could conceptually create building blocks or libraries of RegExp patterns. Finally, as with anyth...
code_snippets
9018d813-1280-4b6c-b005-c83cd7c391c0
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
9
SemanticChunker@1.0.0
a267b8bfeea0c04f837b405a480d5804924859648caf580c840816269fbe9a79
[API design > Function arguments] ### Function arguments One of the make-or-break aspects of any API is the **arguments** of its functions. The amount of them, the ordering, the types, and the defaults all play a role in how easy it is to use the API. **Ambiguity** is the enemy here, but there are other aspects to co...
unknown
unknown
[API design > Function arguments] ### Function arguments One of the make-or-break aspects of any API is the **arguments** of its functions. The amount of them, the ordering, the types, and the defaults all play a role in how easy it is to use the API. **Ambiguity** is the enemy here, but there are other aspects to co...
[API design > Function arguments] ### Function arguments One of the make-or-break aspects of any API is the **arguments** of its functions. The amount of them, the ordering, the types, and the defaults all play a role in how easy it is to use the API. **Ambiguity** is the enemy here, but there are other aspects to co...
code_snippets
9d37b748-3d28-40d0-94ec-19314e23fd41
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
3
SemanticChunker@1.0.0
dae7e3a6147015df4b6b827a8f442cf274eeac4c518d078754364944e29df7f7
[Goal statement > Natural language] ### Natural language As stated before, the main ask is a way to describe regular expressions in a more natural way. To that end, I want to be able to express in code what I would describe to a colleague somewhat familiar with the concept, in **natural language**. This means somethi...
unknown
unknown
[Goal statement > Natural language] ### Natural language As stated before, the main ask is a way to describe regular expressions in a more natural way. To that end, I want to be able to express in code what I would describe to a colleague somewhat familiar with the concept, in **natural language**. This means somethi...
[Goal statement > Natural language] ### Natural language As stated before, the main ask is a way to describe regular expressions in a more natural way. To that end, I want to be able to express in code what I would describe to a colleague somewhat familiar with the concept, in **natural language**. This means somethi...
code_snippets
c0bf4b65-6832-41cc-bae2-f3b600eb3530
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
8
SemanticChunker@1.0.0
404ab21e743d15f421090c35ab49b54954218117815e07103b39877913a6a7f9
[API design > Naming] ### Naming > There are only 2 hard things in Computer Science: cache invalidation & naming things. > > _— Phil Karlton_ Naming is hard, but it's also very important. Remember the original assumption that the end user is somewhat familiar with RegExp? This means we can **use well-established ter...
unknown
unknown
[API design > Naming] ### Naming > There are only 2 hard things in Computer Science: cache invalidation & naming things. > > _— Phil Karlton_ Naming is hard, but it's also very important. Remember the original assumption that the end user is somewhat familiar with RegExp? This means we can **use well-established ter...
[API design > Naming] ### Naming > There are only 2 hard things in Computer Science: cache invalidation & naming things. > > _— Phil Karlton_ Naming is hard, but it's also very important. Remember the original assumption that the end user is somewhat familiar with RegExp? This means we can **use well-established ter...
code_snippets
fb5a43f4-b3c0-40fc-a334-234c9255677f
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/user-centric-api-design.md
unknown
d682ff04-6a32-48dd-952d-9cb0933f636a
13
SemanticChunker@1.0.0
d2532103e4aec1bebc4c3cdd3cb271446734a4fcd145a04f45b3634b4e23c2d9
[Edge cases > Backreferences] #### Backreferences The first case I want to discuss are backreferences. They are a special kind of pattern that refers to a previously captured group. The difference with other patterns is that they are not patterns, but rather a reference to a pattern, either via name or index. @[Quic...
unknown
unknown
[Edge cases > Backreferences] #### Backreferences The first case I want to discuss are backreferences. They are a special kind of pattern that refers to a previously captured group. The difference with other patterns is that they are not patterns, but rather a reference to a pattern, either via name or index. @[Quic...
[Edge cases > Backreferences] #### Backreferences The first case I want to discuss are backreferences. They are a special kind of pattern that refers to a previously captured group. The difference with other patterns is that they are not patterns, but rather a reference to a pattern, either via name or index. @[Quic...
code_snippets
3efc068c-76a8-40ae-8a2c-38e5dca14a60
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/uuid-generator.md
unknown
f1a4470f-4d71-41e2-a947-3185c286c86e
0
SemanticChunker@1.0.0
75ed6acfb57cf3ddda9e39f36e303d94da76b0aabcee1229773a38c3a2507c85
--- title: Generate a UUID in JavaScript shortTitle: Generate UUID language: javascript tags: [browser,node,random] cover: digital-nomad-7 excerpt: Generate a UUID in JavaScript using native APIs in both the browser and Node.js. listed: true dateModified: 2023-12-27 --- A [Universally Unique Identifier (UUID)](https:/...
unknown
unknown
--- title: Generate a UUID in JavaScript shortTitle: Generate UUID language: javascript tags: [browser,node,random] cover: digital-nomad-7 excerpt: Generate a UUID in JavaScript using native APIs in both the browser and Node.js. listed: true dateModified: 2023-12-27 --- A [Universally Unique Identifier (UUID)](https:/...
--- title: Generate a UUID in JavaScript shortTitle: Generate UUID language: javascript tags: [browser,node,random] cover: digital-nomad-7 excerpt: Generate a UUID in JavaScript using native APIs in both the browser and Node.js. listed: true dateModified: 2023-12-27 --- A [Universally Unique Identifier (UUID)](https:/...
code_snippets
6e48e555-1f41-4f54-b400-3535f94d0a81
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/uuid-generator.md
unknown
f1a4470f-4d71-41e2-a947-3185c286c86e
2
SemanticChunker@1.0.0
3c6e56d1c14cadd41b61b57ad4ee1eee0d9946b37855f1b55448674ce700d32c
[Latest browsers & Node.js versions > Older environments] ## Older environments In older environments, generating a UUID is a more complex task. While the technique described below is going to be **less relevant** as time goes by, I think it's still worth documenting. > [!NOTE] > > This technique is the same for bot...
unknown
unknown
[Latest browsers & Node.js versions > Older environments] ## Older environments In older environments, generating a UUID is a more complex task. While the technique described below is going to be **less relevant** as time goes by, I think it's still worth documenting. > [!NOTE] > > This technique is the same for bot...
[Latest browsers & Node.js versions > Older environments] ## Older environments In older environments, generating a UUID is a more complex task. While the technique described below is going to be **less relevant** as time goes by, I think it's still worth documenting. > [!NOTE] > > This technique is the same for bot...
code_snippets
fe09c524-a7fc-4b6f-86e0-245a2ab0c5da
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/uuid-generator.md
unknown
f1a4470f-4d71-41e2-a947-3185c286c86e
1
SemanticChunker@1.0.0
5318b570a672552ac05f15b90b46d13db0a66b0810814d986af505a2cdf2cf2d
[Latest browsers & Node.js versions] ## Latest browsers & Node.js versions Generating a UUID in a modern browser or Node.js is very straightforward. As the **Crypto API** has been standardized you can use the `crypto.randomUUID()` method to generate a UUID. ```js title="Browser" crypto.randomUUID(); // '7982fcfe-572...
unknown
unknown
[Latest browsers & Node.js versions] ## Latest browsers & Node.js versions Generating a UUID in a modern browser or Node.js is very straightforward. As the **Crypto API** has been standardized you can use the `crypto.randomUUID()` method to generate a UUID. ```js title="Browser" crypto.randomUUID(); // '7982fcfe-572...
[Latest browsers & Node.js versions] ## Latest browsers & Node.js versions Generating a UUID in a modern browser or Node.js is very straightforward. As the **Crypto API** has been standardized you can use the `crypto.randomUUID()` method to generate a UUID. ```js title="Browser" crypto.randomUUID(); // '7982fcfe-572...
code_snippets
ae987693-546d-4f14-8298-aeefb3e13053
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/unwind-object.md
unknown
ea25156f-4b95-4841-a8ff-80959210df89
0
SemanticChunker@1.0.0
8a85de072e56b08178670880b2a5cc48a47335290b5145a8c47e11832c054eec
--- title: Unwind a JavaScript object shortTitle: Unwind object language: javascript tags: [object] cover: orange-coffee excerpt: Create an array of objects from an object and one of its array-valued properties. listed: true dateModified: 2024-06-07 --- Given an **object with an array-valued property**, you might want...
unknown
unknown
--- title: Unwind a JavaScript object shortTitle: Unwind object language: javascript tags: [object] cover: orange-coffee excerpt: Create an array of objects from an object and one of its array-valued properties. listed: true dateModified: 2024-06-07 --- Given an **object with an array-valued property**, you might want...
--- title: Unwind a JavaScript object shortTitle: Unwind object language: javascript tags: [object] cover: orange-coffee excerpt: Create an array of objects from an object and one of its array-valued properties. listed: true dateModified: 2024-06-07 --- Given an **object with an array-valued property**, you might want...
code_snippets
04f78089-a88a-481f-829d-886f2cfe352c
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/use-strict.md
unknown
99e66335-e743-469b-b1ba-712e01c4c442
1
SemanticChunker@1.0.0
d30f7ec539d080ea4ba87941fae003dc6d4b08526943648eaf6eeb74ea2744d8
[No accidental global variables] ## No accidental global variables Strict mode makes it impossible to accidentally create global variables due to mistyped variable names. Assignments, which would accidentally create global variables, instead throw an error in strict mode: ```js 'use strict'; myVariable = 42; // The ...
unknown
unknown
[No accidental global variables] ## No accidental global variables Strict mode makes it impossible to accidentally create global variables due to mistyped variable names. Assignments, which would accidentally create global variables, instead throw an error in strict mode: ```js 'use strict'; myVariable = 42; // The ...
[No accidental global variables] ## No accidental global variables Strict mode makes it impossible to accidentally create global variables due to mistyped variable names. Assignments, which would accidentally create global variables, instead throw an error in strict mode: ```js 'use strict'; myVariable = 42; // The ...
code_snippets
0bba077a-0ca5-45c4-89d3-2b8160d79b2f
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/use-strict.md
unknown
99e66335-e743-469b-b1ba-712e01c4c442
0
SemanticChunker@1.0.0
90cfa069fab306deac3e46578859afb94662bd55c0998495e552655f66cb567a
--- title: What does 'use strict' do and what are some of the key benefits to using it? shortTitle: Strict mode introduction language: javascript tags: [function,object] cover: palm-tree-house excerpt: JavaScript's strict mode can make your code faster, cleaner and more secure. listed: true dateModified: 2021-11-28 ---...
unknown
unknown
--- title: What does 'use strict' do and what are some of the key benefits to using it? shortTitle: Strict mode introduction language: javascript tags: [function,object] cover: palm-tree-house excerpt: JavaScript's strict mode can make your code faster, cleaner and more secure. listed: true dateModified: 2021-11-28 ---...
--- title: What does 'use strict' do and what are some of the key benefits to using it? shortTitle: Strict mode introduction language: javascript tags: [function,object] cover: palm-tree-house excerpt: JavaScript's strict mode can make your code faster, cleaner and more secure. listed: true dateModified: 2021-11-28 ---...
code_snippets
230dcccf-f477-440d-97d5-b3841fe7c276
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/use-strict.md
unknown
99e66335-e743-469b-b1ba-712e01c4c442
5
SemanticChunker@1.0.0
e1e63a9d4abb1fc020ae6dca02c5344938b4998e92c1f738485c1035edae8310
[No accidental global variables > No `this` boxing] ## No `this` boxing Strict mode makes JavaScript more secure, by restricting access the global object via `this`. In strict mode, `this` is not boxed (forced into being an object), meaning that if unspecified it will be `undefined` instead of the global object. ```...
unknown
unknown
[No accidental global variables > No `this` boxing] ## No `this` boxing Strict mode makes JavaScript more secure, by restricting access the global object via `this`. In strict mode, `this` is not boxed (forced into being an object), meaning that if unspecified it will be `undefined` instead of the global object. ```...
[No accidental global variables > No `this` boxing] ## No `this` boxing Strict mode makes JavaScript more secure, by restricting access the global object via `this`. In strict mode, `this` is not boxed (forced into being an object), meaning that if unspecified it will be `undefined` instead of the global object. ```...
code_snippets
4c2cbe9e-d4eb-4015-b24a-a05cb2bcc1d5
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/use-strict.md
unknown
99e66335-e743-469b-b1ba-712e01c4c442
4
SemanticChunker@1.0.0
02d9673b659c2fb40da456d8701212db5dc63b2a2902f7258475e19dc65c9e17
[No accidental global variables > Simplified `arguments`] ## Simplified `arguments` Strict mode simplifies `arguments`, by removing some of their side effects. `arguments` aren't aliased, thus they always refer to the original arguments when the function was invoked. Moreover, `arguments.callee` and `arguments.caller...
unknown
unknown
[No accidental global variables > Simplified `arguments`] ## Simplified `arguments` Strict mode simplifies `arguments`, by removing some of their side effects. `arguments` aren't aliased, thus they always refer to the original arguments when the function was invoked. Moreover, `arguments.callee` and `arguments.caller...
[No accidental global variables > Simplified `arguments`] ## Simplified `arguments` Strict mode simplifies `arguments`, by removing some of their side effects. `arguments` aren't aliased, thus they always refer to the original arguments when the function was invoked. Moreover, `arguments.callee` and `arguments.caller...
code_snippets
9b731584-c768-42ee-9256-4c310fb339de
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/use-strict.md
unknown
99e66335-e743-469b-b1ba-712e01c4c442
2
SemanticChunker@1.0.0
18762cf65631f655e64e1274a815b55541510ff1fcdbeae38ec35cbebc0b8aed
[No accidental global variables > Elimination of silent errors] ## Elimination of silent errors Strict mode changes some previously-accepted mistakes into errors. These include: - Assignments which would otherwise silently fail - Deleting undeletable properties or plain names - Duplicated names in function arguments...
unknown
unknown
[No accidental global variables > Elimination of silent errors] ## Elimination of silent errors Strict mode changes some previously-accepted mistakes into errors. These include: - Assignments which would otherwise silently fail - Deleting undeletable properties or plain names - Duplicated names in function arguments...
[No accidental global variables > Elimination of silent errors] ## Elimination of silent errors Strict mode changes some previously-accepted mistakes into errors. These include: - Assignments which would otherwise silently fail - Deleting undeletable properties or plain names - Duplicated names in function arguments...
code_snippets
b915d66d-dd36-4465-b624-9c5c921db8af
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/use-strict.md
unknown
99e66335-e743-469b-b1ba-712e01c4c442
6
SemanticChunker@1.0.0
31fa805576c2b7bd06aed9f6379e345396fa80a44d40666890fe1a9081d52c7e
[No accidental global variables > Other changes] ## Other changes Strict mode implements a few more, less commonly-mentioned changes. These include: - `with` is prohibited, resulting in an error if used - `Function.prototype.arguments` and `Function.prototype.caller` are non-deletable properties which throw when set...
unknown
unknown
[No accidental global variables > Other changes] ## Other changes Strict mode implements a few more, less commonly-mentioned changes. These include: - `with` is prohibited, resulting in an error if used - `Function.prototype.arguments` and `Function.prototype.caller` are non-deletable properties which throw when set...
[No accidental global variables > Other changes] ## Other changes Strict mode implements a few more, less commonly-mentioned changes. These include: - `with` is prohibited, resulting in an error if used - `Function.prototype.arguments` and `Function.prototype.caller` are non-deletable properties which throw when set...
code_snippets
e920b4fe-e77d-446d-90a6-c87142851b53
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/use-strict.md
unknown
99e66335-e743-469b-b1ba-712e01c4c442
3
SemanticChunker@1.0.0
72123a4553ace1ee6fe67e846d2862ffee3a447b0f6a8e50d616c41bfe24349b
[No accidental global variables > Simplified `eval`] ## Simplified `eval` Strict mode makes `eval` more transparent by preventing the introduction of new variables in the surrounding scope. In strict mode, `eval` creates variables only for the code being evaluated. ```js 'use strict'; let x = 1; eval('let x = 3; con...
unknown
unknown
[No accidental global variables > Simplified `eval`] ## Simplified `eval` Strict mode makes `eval` more transparent by preventing the introduction of new variables in the surrounding scope. In strict mode, `eval` creates variables only for the code being evaluated. ```js 'use strict'; let x = 1; eval('let x = 3; con...
[No accidental global variables > Simplified `eval`] ## Simplified `eval` Strict mode makes `eval` more transparent by preventing the introduction of new variables in the surrounding scope. In strict mode, `eval` creates variables only for the code being evaluated. ```js 'use strict'; let x = 1; eval('let x = 3; con...
code_snippets
004c1f17-3f12-44ee-a823-001ed32982b9
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/upperize-lowerize-object-keys.md
unknown
ef72c482-fd75-47eb-8d10-684fb44d40ab
0
SemanticChunker@1.0.0
3564d643869abc621745c9c92b921699a8002f2d7df368b0e6eaa5c385843a7c
--- title: Uppercase or lowercase object keys in JavaScript shortTitle: Uppercase or lowercase object keys language: javascript tags: [object] excerpt: Convert all the keys of an object to upper or lower case. cover: sofia-tram listed: true dateModified: 2024-01-10 --- Data processing often requires transformation of ...
unknown
unknown
--- title: Uppercase or lowercase object keys in JavaScript shortTitle: Uppercase or lowercase object keys language: javascript tags: [object] excerpt: Convert all the keys of an object to upper or lower case. cover: sofia-tram listed: true dateModified: 2024-01-10 --- Data processing often requires transformation of ...
--- title: Uppercase or lowercase object keys in JavaScript shortTitle: Uppercase or lowercase object keys language: javascript tags: [object] excerpt: Convert all the keys of an object to upper or lower case. cover: sofia-tram listed: true dateModified: 2024-01-10 --- Data processing often requires transformation of ...
code_snippets
17fe4e97-e6fd-421f-938f-bcf501332e9e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/upperize-lowerize-object-keys.md
unknown
ef72c482-fd75-47eb-8d10-684fb44d40ab
2
SemanticChunker@1.0.0
4aad5daca26fd28fa7bd7e27ebf67e2c70a2c4770828dab6a2918c9979a74b94
[Uppercase object keys > Lowercase object keys] ## Lowercase object keys Similarly, to convert all the keys of an object to lower case, we can use the same approach. The only notable difference is that we use `String.prototype.toLowerCase()` to lowercase the object's keys. ```js const lowerize = obj => Object.keys(...
unknown
unknown
[Uppercase object keys > Lowercase object keys] ## Lowercase object keys Similarly, to convert all the keys of an object to lower case, we can use the same approach. The only notable difference is that we use `String.prototype.toLowerCase()` to lowercase the object's keys. ```js const lowerize = obj => Object.keys(...
[Uppercase object keys > Lowercase object keys] ## Lowercase object keys Similarly, to convert all the keys of an object to lower case, we can use the same approach. The only notable difference is that we use `String.prototype.toLowerCase()` to lowercase the object's keys. ```js const lowerize = obj => Object.keys(...
code_snippets
8da0f729-3153-474d-b6b9-21353d788e07
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/upperize-lowerize-object-keys.md
unknown
ef72c482-fd75-47eb-8d10-684fb44d40ab
1
SemanticChunker@1.0.0
542bdcfd6827d7137299c4682037a1c77d630bd50f479981af3ca11be4f01643
[Uppercase object keys] ## Uppercase object keys In order to convert all the keys of an object to upper case, we first need to obtain an **array of the object's keys**, using `Object.keys()`. Then, use `Array.prototype.reduce()` to **map the array to an object**, using `String.prototype.toUpperCase()` to uppercase th...
unknown
unknown
[Uppercase object keys] ## Uppercase object keys In order to convert all the keys of an object to upper case, we first need to obtain an **array of the object's keys**, using `Object.keys()`. Then, use `Array.prototype.reduce()` to **map the array to an object**, using `String.prototype.toUpperCase()` to uppercase th...
[Uppercase object keys] ## Uppercase object keys In order to convert all the keys of an object to upper case, we first need to obtain an **array of the object's keys**, using `Object.keys()`. Then, use `Array.prototype.reduce()` to **map the array to an object**, using `String.prototype.toUpperCase()` to uppercase th...
code_snippets
240f215c-270c-4f13-8c78-54ecea505883
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/unit-converter-data-structure.md
unknown
4e775e64-3cac-4415-80a6-f3298363ef0a
0
SemanticChunker@1.0.0
23bfd63803cbd0a0a4369479ed91a7938bbfec080d89b13c10092241a23f8f86
--- title: Create a unit converter data structure in JavaScript shortTitle: Convert between any compatible units language: javascript tags: [math,function] cover: tropical-waterfall-2 excerpt: Learn how to create a unit converter data structure in JavaScript that can convert between any compatible units. listed: true d...
unknown
unknown
--- title: Create a unit converter data structure in JavaScript shortTitle: Convert between any compatible units language: javascript tags: [math,function] cover: tropical-waterfall-2 excerpt: Learn how to create a unit converter data structure in JavaScript that can convert between any compatible units. listed: true d...
--- title: Create a unit converter data structure in JavaScript shortTitle: Convert between any compatible units language: javascript tags: [math,function] cover: tropical-waterfall-2 excerpt: Learn how to create a unit converter data structure in JavaScript that can convert between any compatible units. listed: true d...
code_snippets
6dec70ba-56b7-464f-b5cd-1fe0948c0959
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/unit-converter-data-structure.md
unknown
4e775e64-3cac-4415-80a6-f3298363ef0a
2
SemanticChunker@1.0.0
92df88c6ea440849e2272f741954044833db4250d705e469cf47eff2a7385cca
[Class-based unit converter data structure > Unit converter data structure factory function] ## Unit converter data structure factory function While this works perfectly fine for a specific type of measurement, we have to repeat the whole process for a different type of measurement. This is not ideal, as we can end u...
unknown
unknown
[Class-based unit converter data structure > Unit converter data structure factory function] ## Unit converter data structure factory function While this works perfectly fine for a specific type of measurement, we have to repeat the whole process for a different type of measurement. This is not ideal, as we can end u...
[Class-based unit converter data structure > Unit converter data structure factory function] ## Unit converter data structure factory function While this works perfectly fine for a specific type of measurement, we have to repeat the whole process for a different type of measurement. This is not ideal, as we can end u...
code_snippets
afd162af-ffd9-4605-bdd5-5174240a94dd
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/unit-converter-data-structure.md
unknown
4e775e64-3cac-4415-80a6-f3298363ef0a
1
SemanticChunker@1.0.0
3aa21fa79c1399f20d72c7240cfa0e196c341d87cd1ad44c721cf2d24da22737
[Class-based unit converter data structure] ## Class-based unit converter data structure In its simplest form, any unit-based value is a **numeric value with a unit of measurement** attached to it. Converting from one unit to another is rather simple, so long as the **units are compatible** and you know the **convers...
unknown
unknown
[Class-based unit converter data structure] ## Class-based unit converter data structure In its simplest form, any unit-based value is a **numeric value with a unit of measurement** attached to it. Converting from one unit to another is rather simple, so long as the **units are compatible** and you know the **convers...
[Class-based unit converter data structure] ## Class-based unit converter data structure In its simplest form, any unit-based value is a **numeric value with a unit of measurement** attached to it. Converting from one unit to another is rather simple, so long as the **units are compatible** and you know the **convers...
code_snippets
c18c93d9-5b49-44e4-9707-d81a9cb22548
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/unit-converter-data-structure.md
unknown
4e775e64-3cac-4415-80a6-f3298363ef0a
3
SemanticChunker@1.0.0
6ba8c726d1f8cb98b8d2e0fd1618f41a97842b780a7a2c3f58feb51c49d7aef4
[Class-based unit converter data structure > Unit converter data structure factory function] While this works for **simple formulas**, something like [temperature conversion](/js/s/convert-celsius-fahrenheit) is a bit more complex. I'll not go into further detail here, but I'm sure you can easily figure out the necess...
unknown
unknown
[Class-based unit converter data structure > Unit converter data structure factory function] While this works for **simple formulas**, something like [temperature conversion](/js/s/convert-celsius-fahrenheit) is a bit more complex. I'll not go into further detail here, but I'm sure you can easily figure out the necess...
[Class-based unit converter data structure > Unit converter data structure factory function] While this works for **simple formulas**, something like [temperature conversion](/js/s/convert-celsius-fahrenheit) is a bit more complex. I'll not go into further detail here, but I'm sure you can easily figure out the necess...
code_snippets
285336eb-86e5-40b5-957f-09de0da1cb5d
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/unique-values-in-array-remove-duplicates.md
unknown
655e9bf6-3004-4d89-b52e-ef5810a41e44
1
SemanticChunker@1.0.0
0dbf70e23e5cea033fec17e63e000a4b09a12d3cb633d76ab50be7be6dde8411
[Get all unique values in an array] ## Get all unique values in an array A `Set` **cannot contain duplicate values** and can be easily initialized from the values of an array. Then, as it is **iterable** in itself, we can use the spread operator (`...`) to convert it back to an array of just the unique values. ```js...
unknown
unknown
[Get all unique values in an array] ## Get all unique values in an array A `Set` **cannot contain duplicate values** and can be easily initialized from the values of an array. Then, as it is **iterable** in itself, we can use the spread operator (`...`) to convert it back to an array of just the unique values. ```js...
[Get all unique values in an array] ## Get all unique values in an array A `Set` **cannot contain duplicate values** and can be easily initialized from the values of an array. Then, as it is **iterable** in itself, we can use the spread operator (`...`) to convert it back to an array of just the unique values. ```js...
code_snippets
4fc47f6f-a0b8-44ab-8fca-7d467b893b5c
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/unique-values-in-array-remove-duplicates.md
unknown
655e9bf6-3004-4d89-b52e-ef5810a41e44
2
SemanticChunker@1.0.0
0115fd0f93f21d816a6bd0c759d2b7a5652218eeb9ac86d6ed026f42588809e3
[Get all unique values in an array > Check if an array contains duplicates] ## Check if an array contains duplicates `Set` doesn't have a `length` property, but it does have a `size` property, instead. We can use this to check if an array contains duplicates. ```js const hasDuplicates = arr => arr.length !== new Set...
unknown
unknown
[Get all unique values in an array > Check if an array contains duplicates] ## Check if an array contains duplicates `Set` doesn't have a `length` property, but it does have a `size` property, instead. We can use this to check if an array contains duplicates. ```js const hasDuplicates = arr => arr.length !== new Set...
[Get all unique values in an array > Check if an array contains duplicates] ## Check if an array contains duplicates `Set` doesn't have a `length` property, but it does have a `size` property, instead. We can use this to check if an array contains duplicates. ```js const hasDuplicates = arr => arr.length !== new Set...
code_snippets
710204de-c74c-4c90-8498-2d6b7c2b7d5e
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/unique-values-in-array-remove-duplicates.md
unknown
655e9bf6-3004-4d89-b52e-ef5810a41e44
3
SemanticChunker@1.0.0
956a674292da2dc73094e976d971790a0661e8d78776eff0a67f28e2ffdb25c4
[Get all unique values in an array > Remove array values that appear more than once] ## Remove array values that appear more than once If we want to keep only values that are not duplicated, we can use the `Array.prototype.filter()` method. Elements that appear more than once have to appear in **at least two differen...
unknown
unknown
[Get all unique values in an array > Remove array values that appear more than once] ## Remove array values that appear more than once If we want to keep only values that are not duplicated, we can use the `Array.prototype.filter()` method. Elements that appear more than once have to appear in **at least two differen...
[Get all unique values in an array > Remove array values that appear more than once] ## Remove array values that appear more than once If we want to keep only values that are not duplicated, we can use the `Array.prototype.filter()` method. Elements that appear more than once have to appear in **at least two differen...
code_snippets
c0a019bc-eeb2-49b1-9d84-adebf0943bd5
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/unique-values-in-array-remove-duplicates.md
unknown
655e9bf6-3004-4d89-b52e-ef5810a41e44
4
SemanticChunker@1.0.0
1473bdf032faf43e61c3184ef71624a75f785192f14b04922ebad8db908b5ff7
[Get all unique values in an array > Using a function to find duplicates] ## Using a function to find duplicates More complex data, such as objects, can't be compared using equality comparison, so we need to use a function to check for duplicates. `Set` objects are not much use here, so we can use `Array.prototype.re...
unknown
unknown
[Get all unique values in an array > Using a function to find duplicates] ## Using a function to find duplicates More complex data, such as objects, can't be compared using equality comparison, so we need to use a function to check for duplicates. `Set` objects are not much use here, so we can use `Array.prototype.re...
[Get all unique values in an array > Using a function to find duplicates] ## Using a function to find duplicates More complex data, such as objects, can't be compared using equality comparison, so we need to use a function to check for duplicates. `Set` objects are not much use here, so we can use `Array.prototype.re...
code_snippets
e5e2e045-1a21-48c8-b5cc-e762a1a66f4f
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/unique-values-in-array-remove-duplicates.md
unknown
655e9bf6-3004-4d89-b52e-ef5810a41e44
0
SemanticChunker@1.0.0
77280b35796228670ba44329b56f4ee70c42be7f96e19192db8b2463aef430a9
--- title: Get all unique values in a JavaScript array & remove duplicates shortTitle: Unique array values language: javascript tags: [array] cover: architectural excerpt: Easily remove duplicates from a JavaScript array using the built-in `Set` object, and learn a few other tricks along the way. listed: true dateModif...
unknown
unknown
--- title: Get all unique values in a JavaScript array & remove duplicates shortTitle: Unique array values language: javascript tags: [array] cover: architectural excerpt: Easily remove duplicates from a JavaScript array using the built-in `Set` object, and learn a few other tricks along the way. listed: true dateModif...
--- title: Get all unique values in a JavaScript array & remove duplicates shortTitle: Unique array values language: javascript tags: [array] cover: architectural excerpt: Easily remove duplicates from a JavaScript array using the built-in `Set` object, and learn a few other tricks along the way. listed: true dateModif...
code_snippets
020e17fc-900e-4281-a5b3-6b3821da11df
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-from-edges.md
unknown
5852327b-544e-4596-853c-f8293594a240
6
SemanticChunker@1.0.0
38189fbb59965aa30e47738e3b34c07f497ecf02bf465955accf694db0c9af7d
[Building the tree > Reachable nodes] ### Reachable nodes In the same vein, if you need to find all reachable nodes from a given node, you can **store all reachable nodes**, including the node itself. This is particularly useful for problems that require you to find all nodes within a certain distance from a starting...
unknown
unknown
[Building the tree > Reachable nodes] ### Reachable nodes In the same vein, if you need to find all reachable nodes from a given node, you can **store all reachable nodes**, including the node itself. This is particularly useful for problems that require you to find all nodes within a certain distance from a starting...
[Building the tree > Reachable nodes] ### Reachable nodes In the same vein, if you need to find all reachable nodes from a given node, you can **store all reachable nodes**, including the node itself. This is particularly useful for problems that require you to find all nodes within a certain distance from a starting...
code_snippets
3a83bd70-b9fe-4ae6-9a7c-fd270acfd86c
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-from-edges.md
unknown
5852327b-544e-4596-853c-f8293594a240
5
SemanticChunker@1.0.0
219ac892574b336cc74dd5cedd1d5d102aa1f36692d29b1b145327e540d8ce96
[Building the tree > Parent and children] ### Parent and children When you need to traverse the tree in both directions, it can be useful to **store both the node's parent and children**. This allows you to easily navigate the tree in either direction, which can be helpful for certain algorithms or when you need to f...
unknown
unknown
[Building the tree > Parent and children] ### Parent and children When you need to traverse the tree in both directions, it can be useful to **store both the node's parent and children**. This allows you to easily navigate the tree in either direction, which can be helpful for certain algorithms or when you need to f...
[Building the tree > Parent and children] ### Parent and children When you need to traverse the tree in both directions, it can be useful to **store both the node's parent and children**. This allows you to easily navigate the tree in either direction, which can be helpful for certain algorithms or when you need to f...
code_snippets
3f39858c-f6fa-49cc-8a0d-bb93ca176583
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-from-edges.md
unknown
5852327b-544e-4596-853c-f8293594a240
2
SemanticChunker@1.0.0
8ce2863d95eae4aa861e95bcf63f004abe29ba4f41d675f76e85953af58aeb65
[Undirected trees > Building the tree] ## Building the tree In most cases, one can simply get away without creating a full data structure, like we've done in the [previous article](/js/s/data-structures-tree), but rather use a simple `Map` to represent the edges in a usable way. Each node will be a map key, and the c...
unknown
unknown
[Undirected trees > Building the tree] ## Building the tree In most cases, one can simply get away without creating a full data structure, like we've done in the [previous article](/js/s/data-structures-tree), but rather use a simple `Map` to represent the edges in a usable way. Each node will be a map key, and the c...
[Undirected trees > Building the tree] ## Building the tree In most cases, one can simply get away without creating a full data structure, like we've done in the [previous article](/js/s/data-structures-tree), but rather use a simple `Map` to represent the edges in a usable way. Each node will be a map key, and the c...
code_snippets
5de49310-7700-4477-87c7-89239e0d57ea
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-from-edges.md
unknown
5852327b-544e-4596-853c-f8293594a240
3
SemanticChunker@1.0.0
99a8ff4b2c942fb3987349f6d5de95b451c91c9ab7f0803fffb2266292fbe450
[Building the tree > Children] ### Children By far the most common strategy is **storing only the node's children**. This allows us to easily traverse the tree downwards, which is often the most useful direction for many algorithms. ```js const edgesToChildGraph = edges => edges.reduce((acc, [a, b]) => { if (!acc....
unknown
unknown
[Building the tree > Children] ### Children By far the most common strategy is **storing only the node's children**. This allows us to easily traverse the tree downwards, which is often the most useful direction for many algorithms. ```js const edgesToChildGraph = edges => edges.reduce((acc, [a, b]) => { if (!acc....
[Building the tree > Children] ### Children By far the most common strategy is **storing only the node's children**. This allows us to easily traverse the tree downwards, which is often the most useful direction for many algorithms. ```js const edgesToChildGraph = edges => edges.reduce((acc, [a, b]) => { if (!acc....
code_snippets
7b0025f4-64c8-4cc9-b9d4-6533811cbf1d
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-from-edges.md
unknown
5852327b-544e-4596-853c-f8293594a240
4
SemanticChunker@1.0.0
3b101c36c31a2a6cd42a132a1fa4d706ab11a499c2bbaf1cc2cb42dabe84dfd3
[Building the tree > Parent] ### Parent When you need to traverse the tree upwards, it can be useful to **store only the node's parent**. This allows you to easily find the parent of any given node, which can be helpful in certain algorithms or when you need to backtrack. ```js const edgesToParentGraph = edges => e...
unknown
unknown
[Building the tree > Parent] ### Parent When you need to traverse the tree upwards, it can be useful to **store only the node's parent**. This allows you to easily find the parent of any given node, which can be helpful in certain algorithms or when you need to backtrack. ```js const edgesToParentGraph = edges => e...
[Building the tree > Parent] ### Parent When you need to traverse the tree upwards, it can be useful to **store only the node's parent**. This allows you to easily find the parent of any given node, which can be helpful in certain algorithms or when you need to backtrack. ```js const edgesToParentGraph = edges => e...
code_snippets
845c8735-189e-44aa-8d7f-68dde2412ac4
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-from-edges.md
unknown
5852327b-544e-4596-853c-f8293594a240
0
SemanticChunker@1.0.0
f512c62357c3ccbcb00fd7a5281df0decc27fe7175a0bb5c9f330f40ebcda5e4
--- title: How can I build an undirected tree from an array of edges in JavaScript? shortTitle: Undirected tree from edges language: javascript tags: [array] cover: walking-sunrise excerpt: Learn how to build an undirected tree from an array of edges in JavaScript, with various approaches for storing node relationships...
unknown
unknown
--- title: How can I build an undirected tree from an array of edges in JavaScript? shortTitle: Undirected tree from edges language: javascript tags: [array] cover: walking-sunrise excerpt: Learn how to build an undirected tree from an array of edges in JavaScript, with various approaches for storing node relationships...
--- title: How can I build an undirected tree from an array of edges in JavaScript? shortTitle: Undirected tree from edges language: javascript tags: [array] cover: walking-sunrise excerpt: Learn how to build an undirected tree from an array of edges in JavaScript, with various approaches for storing node relationships...
code_snippets
9432d7c5-00a0-4deb-a524-d906f7788012
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-from-edges.md
unknown
5852327b-544e-4596-853c-f8293594a240
7
SemanticChunker@1.0.0
970d3bcd345bb3a41ddd97c3c5a6d8dc8ba7f1e2213f2317678c020f419d2349
[Undirected trees > Conclusion] ## Conclusion Building an undirected tree from an array of edges in JavaScript can be done in various ways, depending on your specific needs. Whether you need to traverse the tree downwards, upwards, or in both directions, you can choose the appropriate structure to represent the tree....
unknown
unknown
[Undirected trees > Conclusion] ## Conclusion Building an undirected tree from an array of edges in JavaScript can be done in various ways, depending on your specific needs. Whether you need to traverse the tree downwards, upwards, or in both directions, you can choose the appropriate structure to represent the tree....
[Undirected trees > Conclusion] ## Conclusion Building an undirected tree from an array of edges in JavaScript can be done in various ways, depending on your specific needs. Whether you need to traverse the tree downwards, upwards, or in both directions, you can choose the appropriate structure to represent the tree....
code_snippets
97580cd0-ec60-4360-a50a-0e039aa2ffa4
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-from-edges.md
unknown
5852327b-544e-4596-853c-f8293594a240
1
SemanticChunker@1.0.0
11ad84d162b0ae7a309fb58a0fd93f857b1322e636a7c5af51eb53acf41f6e85
[Undirected trees] ## Undirected trees Before we delve into the code, I'd like to note that, for a tree with `n` **vertices**, the number of **edges** is exactly `n - 1`. This is a fundamental property of trees, and it helps us ensure that we are indeed building a **valid tree structure**. It can also help us allocat...
unknown
unknown
[Undirected trees] ## Undirected trees Before we delve into the code, I'd like to note that, for a tree with `n` **vertices**, the number of **edges** is exactly `n - 1`. This is a fundamental property of trees, and it helps us ensure that we are indeed building a **valid tree structure**. It can also help us allocat...
[Undirected trees] ## Undirected trees Before we delve into the code, I'd like to note that, for a tree with `n` **vertices**, the number of **edges** is exactly `n - 1`. This is a fundamental property of trees, and it helps us ensure that we are indeed building a **valid tree structure**. It can also help us allocat...
code_snippets
512dbbe8-ce3e-4801-87bc-f7bc578cb6e1
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-diameter.md
unknown
0901cf96-c08d-4b82-850b-0da42ec172ee
3
SemanticChunker@1.0.0
aee73f9bfc5c0ca1327d6ceef2a246e2d2d31db107b8cbe29daa937a7712b0bd
[Diameter of an undirected tree > Implementation] ``` As you can see, with a few small tweaks to our DFS implementation, we can efficiently find the diameter of an undirected tree. The **first pass** finds the farthest node from the starting node, using the distance to track how far we are from the starting point. W...
unknown
unknown
[Diameter of an undirected tree > Implementation] ``` As you can see, with a few small tweaks to our DFS implementation, we can efficiently find the diameter of an undirected tree. The **first pass** finds the farthest node from the starting node, using the distance to track how far we are from the starting point. W...
[Diameter of an undirected tree > Implementation] ``` As you can see, with a few small tweaks to our DFS implementation, we can efficiently find the diameter of an undirected tree. The **first pass** finds the farthest node from the starting node, using the distance to track how far we are from the starting point. W...
code_snippets
530e17f6-9f11-4798-9292-a2c933a50dba
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-diameter.md
unknown
0901cf96-c08d-4b82-850b-0da42ec172ee
1
SemanticChunker@1.0.0
f91c68e4d91a93878bb6c79d78bec08d195b3000a80972664646762e118d6924
[Diameter of an undirected tree] ## Diameter of an undirected tree The diameter of an undirected tree is defined as the **longest path between any two nodes** in the tree. In other words, it's the **maximum number of edges** that need to be traversed to go from one node to another in the tree. Let's look at an exampl...
unknown
unknown
[Diameter of an undirected tree] ## Diameter of an undirected tree The diameter of an undirected tree is defined as the **longest path between any two nodes** in the tree. In other words, it's the **maximum number of edges** that need to be traversed to go from one node to another in the tree. Let's look at an exampl...
[Diameter of an undirected tree] ## Diameter of an undirected tree The diameter of an undirected tree is defined as the **longest path between any two nodes** in the tree. In other words, it's the **maximum number of edges** that need to be traversed to go from one node to another in the tree. Let's look at an exampl...
code_snippets
a270a1f5-2765-4640-bdc6-3e13d0f6747b
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-diameter.md
unknown
0901cf96-c08d-4b82-850b-0da42ec172ee
2
SemanticChunker@1.0.0
e7c34d0236ba9fda3c2f4a007e4085063dfe52603ac4c3df85afc51f9d9c534b
[Diameter of an undirected tree > Implementation] ## Implementation To find the diameter of an undirected tree, we can use a **two-pass DFS approach**. The first pass will find the **farthest node from an arbitrary starting node**, and the second pass will find the **farthest node from that node**, which will give us...
unknown
unknown
[Diameter of an undirected tree > Implementation] ## Implementation To find the diameter of an undirected tree, we can use a **two-pass DFS approach**. The first pass will find the **farthest node from an arbitrary starting node**, and the second pass will find the **farthest node from that node**, which will give us...
[Diameter of an undirected tree > Implementation] ## Implementation To find the diameter of an undirected tree, we can use a **two-pass DFS approach**. The first pass will find the **farthest node from an arbitrary starting node**, and the second pass will find the **farthest node from that node**, which will give us...
code_snippets
ac1a78a0-1141-4243-ac87-9ce158efffd5
unknown
file:///home/sanjeev/Downloads/depthapi/datasets/30-seconds-of-code/content/snippets/js/s/undirected-tree-diameter.md
unknown
0901cf96-c08d-4b82-850b-0da42ec172ee
0
SemanticChunker@1.0.0
b0d1c11af4689194256921c49df1988dcf34f5c9ddc8d43e4a99b5f533527b9c
--- title: How can I find the diameter of an undirected tree in JavaScript? shortTitle: Undirected tree diameter language: javascript tags: [algorithm,array] cover: laptop-off-2 excerpt: Using a two-pass DFS approach, we can efficiently find the diameter of an undirected tree in JavaScript. listed: true dateModified: 2...
unknown
unknown
--- title: How can I find the diameter of an undirected tree in JavaScript? shortTitle: Undirected tree diameter language: javascript tags: [algorithm,array] cover: laptop-off-2 excerpt: Using a two-pass DFS approach, we can efficiently find the diameter of an undirected tree in JavaScript. listed: true dateModified: 2...
--- title: How can I find the diameter of an undirected tree in JavaScript? shortTitle: Undirected tree diameter language: javascript tags: [algorithm,array] cover: laptop-off-2 excerpt: Using a two-pass DFS approach, we can efficiently find the diameter of an undirected tree in JavaScript. listed: true dateModified: 2...
code_snippets