diff --git a/README.md b/README.md index 39b722e10..a8e3378f0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ * Visit [our website](https://30secondsofcode.org) to view our snippet collection. * Search for snippets that suit your needs. You can search by name, tag, language or using a snippet's description. Just start typing a term and see what comes up. -* Browse the [Snippet collection](https://30secondsofcode.org/list/p/1) to see all the snippets or click individual tags at the top of the same page to narrow down your search to a specific tag. +* Browse all [snippets](https://30secondsofcode.org/snippes/p/1) or individual [snippet collections](https://30secondsofcode.org/collections/p/1) for each topic. * Click on each snippet card to view the whole snippet, including code, explanation and examples. * You can copy code blocks on any snippet card, using the copy button at the top right. * If you like the project, give it a star. It means a lot to the people maintaining it. diff --git a/collections/css/centering.yaml b/collections/css/centering.yaml index 7d9e3cca6..0bd1896b0 100644 --- a/collections/css/centering.yaml +++ b/collections/css/centering.yaml @@ -2,7 +2,7 @@ slug: css/centering name: CSS Centering featured: true snippetIds: - - articles/s/css-centering + - css/s/centering - css/s/flexbox-centering - css/s/grid-centering - css/s/transform-centering diff --git a/collections/js/array-initialization.yaml b/collections/js/array-initialization.yaml index ce70236c7..277bd7e5c 100644 --- a/collections/js/array-initialization.yaml +++ b/collections/js/array-initialization.yaml @@ -2,15 +2,15 @@ slug: js/array-initialization name: JavaScript Array Initialization featured: true snippetIds: - - articles/s/js-array-initialization + - js/s/array-initialization - js/s/initialize-array-with-values - js/s/initialize-array-with-range - - js/s/initialize-array-with-range-right + - js/s/initialize-array-with-reversed-range - js/s/initialize-mapped-array - js/s/initialize-array-while - js/s/initialize-array-until - - js/s/initialize2-d-array - - js/s/initialize-nd-array + - js/s/initialize-2d-array + - js/s/initialize-n-dimensional-array splash: laptop-lamp.png description: >- When it comes to array initialization in JavaScript, there are as many options diff --git a/collections/js/array-methods.yaml b/collections/js/array-methods.yaml index 11584a557..a97f56d8a 100644 --- a/collections/js/array-methods.yaml +++ b/collections/js/array-methods.yaml @@ -2,15 +2,15 @@ slug: js/array-methods name: JavaScript Array Methods featured: true snippetIds: - - articles/s/js-array-map-vs-foreach - - articles/s/4-javascript-array-methods - - articles/s/javascript-array-comparison - - articles/s/javascript-index-for-of-loop - - articles/s/javascript-for-loop-early-break - - articles/s/js-array-initialization - - articles/s/code-anatomy-chaining-reduce-for-loop - - articles/s/javascript-async-array-loops - - articles/s/js-typecheck-array + - js/s/array-map-vs-foreach + - js/s/4-array-methods + - js/s/array-comparison + - js/s/index-for-of-loop + - js/s/for-loop-early-break + - js/s/array-initialization + - js/s/code-anatomy-chaining-reduce-for-loop + - js/s/async-array-loops + - js/s/typecheck-array splash: laptop-lamp.png description: >- JavaScript arrays offer a lot of data manipulation and transformation methods. diff --git a/collections/js/array-set-operations.yaml b/collections/js/array-set-operations.yaml index 3964bfd03..1c46b6a67 100644 --- a/collections/js/array-set-operations.yaml +++ b/collections/js/array-set-operations.yaml @@ -2,18 +2,18 @@ slug: js/array-set-operations name: JavaScript Array Set Operations featured: true snippetIds: - - js/s/union - - js/s/intersection - - js/s/difference - - js/s/symmetric-difference - - js/s/union-by - - js/s/intersection-by - - js/s/difference-by - - js/s/symmetric-difference-by - - js/s/union-with - - js/s/intersection-with - - js/s/difference-with - - js/s/symmetric-difference-with + - js/s/array-union + - js/s/array-intersection + - js/s/array-difference + - js/s/array-symmetric-difference + - js/s/mapped-array-union + - js/s/mapped-array-intersection + - js/s/mapped-array-difference + - js/s/mapped-array-symmetric-difference + - js/s/function-based-array-union + - js/s/function-based-array-intersection + - js/s/function-based-array-difference + - js/s/function-based-array-symmetric-difference splash: touch-flower.png description: >- Mathematical set operations can be easily applied to JavaScript arrays. Learn diff --git a/collections/js/array-tricks.yaml b/collections/js/array-tricks.yaml index 6aa1c232e..76f3819ce 100644 --- a/collections/js/array-tricks.yaml +++ b/collections/js/array-tricks.yaml @@ -2,18 +2,18 @@ slug: js/array-tricks name: JavaScript Array Tricks featured: true snippetIds: - - js/s/unique-elements - - js/s/compact - - js/s/any - - js/s/all - - js/s/none - - js/s/difference - - js/s/union - - js/s/intersection - - js/s/head - - js/s/tail - - js/s/last - - js/s/flatten + - js/s/unique-elements-in-array + - js/s/compact-array + - js/s/any-array-element-is-truthy + - js/s/all-array-elements-are-truthy + - js/s/all-array-elements-are-falsy + - js/s/array-difference + - js/s/array-union + - js/s/array-intersection + - js/s/array-head + - js/s/array-tail + - js/s/last-array-element + - js/s/flatten-array splash: terrarium.png description: >- Arrays are one of the most common data types in JavaScript. While there are diff --git a/collections/js/arrow-functions.yaml b/collections/js/arrow-functions.yaml index a85355dd7..b707a1cea 100644 --- a/collections/js/arrow-functions.yaml +++ b/collections/js/arrow-functions.yaml @@ -2,10 +2,10 @@ slug: js/arrow-functions name: JavaScript Arrow Functions featured: true snippetIds: - - articles/s/javascript-arrow-functions - - articles/s/javascript-arrow-regular-function-differences - - articles/s/javascript-arrow-function-event-listeners - - articles/s/javascript-this + - js/s/arrow-functions + - js/s/arrow-regular-function-differences + - js/s/arrow-function-event-listeners + - js/s/this splash: coffee-float.png description: >- Arrow functions are one of the most useful tools in a JavaScript developer's diff --git a/collections/js/comparison.yaml b/collections/js/comparison.yaml index 2cf8e48f0..845a23999 100644 --- a/collections/js/comparison.yaml +++ b/collections/js/comparison.yaml @@ -2,17 +2,17 @@ slug: js/comparison name: JavaScript Comparison featured: true snippetIds: - - articles/s/javascript-equality - - articles/s/javascript-value-not-equal-to-itself - - articles/s/javascript-object-comparison - - articles/s/javascript-array-comparison - - articles/s/javascript-date-comparison - - articles/s/javascript-object-is-triple-equals - - js/s/equals - - js/s/matches - - js/s/matches-with - - js/s/have-same-contents - - js/s/is-same-date + - js/s/equality + - js/s/value-not-equal-to-itself + - js/s/object-comparison + - js/s/array-comparison + - js/s/date-comparison + - js/s/object-is-triple-equals + - js/s/deep-equality-comparison + - js/s/match-object-properties + - js/s/function-based-object-property-matches + - js/s/arrays-have-same-contents + - js/s/date-is-same-as-another-date splash: succulent.png description: >- Comparing values in JavaScript is one of the most common tasks. Yet, there are diff --git a/collections/js/css-manipulation.yaml b/collections/js/css-manipulation.yaml index 3d0fa7535..748c252ad 100644 --- a/collections/js/css-manipulation.yaml +++ b/collections/js/css-manipulation.yaml @@ -2,18 +2,18 @@ slug: js/css-manipulation name: CSS Manipulation with JavaScript featured: true snippetIds: - - js/s/toggle-class - - js/s/add-class - - js/s/remove-class - - js/s/has-class + - js/s/toggle-html-element-class + - js/s/add-class-to-html-element + - js/s/remove-class-from-html-element + - js/s/html-element-has-class - js/s/get-style - - js/s/set-style - - js/s/add-styles + - js/s/set-style-for-html-element + - js/s/add-styles-to-html-element - js/s/inject-css - - js/s/hide - - js/s/show + - js/s/hide-html-elements + - js/s/show-html-elements - js/s/remove-attributes - - js/s/prefix + - js/s/prefix-css-property splash: planning.png description: >- Unlock the power of manipulating CSS in the browser, using JavaScript. From diff --git a/collections/js/data-structures.yaml b/collections/js/data-structures.yaml index 06a67cceb..a68c40c39 100644 --- a/collections/js/data-structures.yaml +++ b/collections/js/data-structures.yaml @@ -4,17 +4,17 @@ miniName: Data Structures parent: js featured: true snippetIds: - - articles/s/js-native-data-structures - - articles/s/js-data-structures-queue - - articles/s/js-data-structures-stack - - articles/s/js-data-structures-linked-list - - articles/s/js-data-structures-doubly-linked-list - - articles/s/js-data-structures-graph - - articles/s/js-data-structures-tree - - articles/s/js-data-structures-binary-tree - - articles/s/js-data-structures-binary-search-tree - - articles/s/js-frequency-map-data-structure - - articles/s/big-o-cheatsheet + - js/s/native-data-structures + - js/s/data-structures-queue + - js/s/data-structures-stack + - js/s/data-structures-linked-list + - js/s/data-structures-doubly-linked-list + - js/s/data-structures-graph + - js/s/data-structures-tree + - js/s/data-structures-binary-tree + - js/s/data-structures-binary-search-tree + - js/s/frequency-map-data-structure + - js/s/big-o-cheatsheet splash: purple-flower.png description: >- The JavaScript data structures collection includes implementations and diff --git a/collections/js/dom-manipulation.yaml b/collections/js/dom-manipulation.yaml index 0839aa43b..0be16c04a 100644 --- a/collections/js/dom-manipulation.yaml +++ b/collections/js/dom-manipulation.yaml @@ -2,12 +2,12 @@ slug: js/dom-manipulation name: JavaScript DOM Manipulation featured: true snippetIds: - - articles/s/js-create-element + - js/s/create-html-elements - js/s/create-element - - js/s/remove-element - - js/s/insert-after - - js/s/insert-before - - js/s/render-element + - js/s/remove-dom-element + - js/s/insert-html-string-after-element + - js/s/insert-html-string-before-element + - js/s/render-dom-element splash: hiking-balance.png description: >- DOM manipulation is a core skill for any web developer. Learn how to diff --git a/collections/js/dom-querying.yaml b/collections/js/dom-querying.yaml index ac17ac732..ddfa85167 100644 --- a/collections/js/dom-querying.yaml +++ b/collections/js/dom-querying.yaml @@ -9,14 +9,14 @@ snippetIds: - js/s/element-contains - js/s/find-closest-anchor - js/s/get-images - - articles/s/javascript-query-selector-shorthand + - js/s/query-selector-shorthand - js/s/element-is-visible-in-viewport - - articles/s/select-focused-dom-element + - js/s/select-focused-dom-element - js/s/get-elements-bigger-than-viewport - - articles/s/js-element-from-point + - js/s/element-from-point - js/s/element-is-focused - js/s/get-vertical-offset - - articles/s/javascript-store-dom-items + - js/s/store-dom-items splash: laptop-plants-1.png description: >- Querying the DOM is an essential skill every web developer should have. Learn diff --git a/collections/js/event-handling.yaml b/collections/js/event-handling.yaml index b1d7fa8fd..dec7357ae 100644 --- a/collections/js/event-handling.yaml +++ b/collections/js/event-handling.yaml @@ -2,19 +2,19 @@ slug: js/event-handling name: JavaScript Event Handling featured: true snippetIds: - - js/s/on - - js/s/off + - js/s/add-event-listener + - js/s/remove-event-listener - js/s/listen-once - js/s/on-click-outside - - articles/s/javascript-event-bubbling-capturing-delegation + - js/s/event-bubbling-capturing-delegation - js/s/add-event-listener-all - - js/s/remove-event-listener-all - - js/s/add-multiple-events - - articles/s/javascript-listen-once - - articles/s/passive-scroll-listener-performance + - js/s/remove-multiple-event-listeners + - js/s/add-multiple-event-listeners + - js/s/execute-event-handler-once + - js/s/passive-scroll-listener-performance - js/s/on-scroll-stop - - articles/s/javascript-arrow-function-event-listeners - - articles/s/detect-caps-lock-is-on + - js/s/arrow-function-event-listeners + - js/s/detect-caps-lock-is-on - js/s/trigger-event - js/s/on-user-input-change splash: monsterra.png diff --git a/collections/js/generators.yaml b/collections/js/generators.yaml index 476043c9b..83e31895f 100644 --- a/collections/js/generators.yaml +++ b/collections/js/generators.yaml @@ -2,23 +2,23 @@ slug: js/generators name: JavaScript Generator Functions featured: true snippetIds: - - articles/s/javascript-range-generator + - js/s/generator-for-range - js/s/range-generator - js/s/repeat-generator - js/s/cycle-generator - js/s/generator-to-array - js/s/is-generator-function - - js/s/chunkify + - js/s/chunk-iterable - js/s/date-range-generator - js/s/index-of-substrings - - js/s/walk-through + - js/s/walk-through-object - js/s/generate-while - js/s/generate-until - - js/s/left-substr-generator - - js/s/right-substr-generator - - articles/s/javascript-make-iterable - - articles/s/javascript-enum - - articles/s/javascript-object-array-proxy + - js/s/left-substring-generator + - js/s/right-substring-generator + - js/s/make-iterable + - js/s/enum + - js/s/object-array-proxy splash: generator.png description: >- JavaScript generator functions introduce a way to define an iterative diff --git a/collections/js/http-requests.yaml b/collections/js/http-requests.yaml index a3ebe3632..c8b866a7e 100644 --- a/collections/js/http-requests.yaml +++ b/collections/js/http-requests.yaml @@ -7,7 +7,7 @@ snippetIds: - js/s/http-put - js/s/http-delete - articles/s/http-status-codes-cheatsheet - - articles/s/cors-explained + - js/s/cors-explained splash: laptop-plants-1.png description: >- Making network requests is a crucial part of most web applications. This diff --git a/collections/js/interviews.yaml b/collections/js/interviews.yaml index f051ee366..4cca596ed 100644 --- a/collections/js/interviews.yaml +++ b/collections/js/interviews.yaml @@ -4,39 +4,39 @@ miniName: Interview Questions featured: true parent: js snippetIds: - - articles/s/javascript-equality - - articles/s/javascript-truthy-falsy-values - - articles/s/javascript-expression-statement - - articles/s/javascript-undeclared-undefined-null - - articles/s/javascript-variable-hoisting - - articles/s/javascript-variable-scope - - articles/s/js-callbacks - - articles/s/javascript-pass-by-reference-or-pass-by-value - - articles/s/javascript-promises - - articles/s/javascript-sync-async - - articles/s/javascript-classical-vs-prototypal-inheritance - - articles/s/javascript-this - - articles/s/javascript-shallow-deep-clone - - articles/s/javascript-copy-array - - articles/s/javascript-object-comparison - - articles/s/javascript-array-comparison - - articles/s/javascript-array-includes-value - - articles/s/js-array-map-vs-foreach - - articles/s/javascript-event-bubbling-capturing-delegation - - articles/s/javascript-value-not-equal-to-itself - - articles/s/javascript-blank-value - - articles/s/javascript-string-immutability - - articles/s/js-static-instance-methods - - articles/s/javascript-arrow-functions - - articles/s/javascript-pure-functions - - articles/s/javascript-recursion - - articles/s/javascript-use-strict - - articles/s/js-async-defer - - articles/s/javascript-closures - - articles/s/javascript-iife - - articles/s/javascript-event-loop-explained - - articles/s/javascript-prefix-postfix-operators - - articles/s/cors-explained + - js/s/equality + - js/s/truthy-falsy-values + - js/s/expression-statement + - js/s/undeclared-undefined-null + - js/s/variable-hoisting + - js/s/variable-scope + - js/s/callbacks + - js/s/pass-by-reference-or-pass-by-value + - js/s/promises + - js/s/sync-async + - js/s/classical-vs-prototypal-inheritance + - js/s/this + - js/s/shallow-deep-clone + - js/s/copy-array + - js/s/object-comparison + - js/s/array-comparison + - js/s/array-includes-value + - js/s/array-map-vs-foreach + - js/s/event-bubbling-capturing-delegation + - js/s/value-not-equal-to-itself + - js/s/blank-value + - js/s/string-immutability + - js/s/static-instance-methods + - js/s/arrow-functions + - js/s/pure-functions + - js/s/recursion + - js/s/use-strict + - js/s/async-defer + - js/s/closures + - js/s/iife + - js/s/event-loop-explained + - js/s/prefix-postfix-operators + - js/s/cors-explained splash: interview.png description: >- Preparing for a job interview requires studying to refresh your knowledge and diff --git a/collections/js/logical-operations.yaml b/collections/js/logical-operations.yaml index 299fec6d3..cc6fcf72e 100644 --- a/collections/js/logical-operations.yaml +++ b/collections/js/logical-operations.yaml @@ -7,10 +7,10 @@ snippetIds: - js/s/not - js/s/xor - js/s/nor - - js/s/when + - js/s/conditionally-apply-function - js/s/both - - js/s/either - - js/s/complement + - js/s/function-logical-or + - js/s/logical-complement splash: chess-pawns.png description: >- Boolean logic and logical operations might not come up that often in diff --git a/collections/js/object-cloning.yaml b/collections/js/object-cloning.yaml index 5f4e866e1..2e6d594ca 100644 --- a/collections/js/object-cloning.yaml +++ b/collections/js/object-cloning.yaml @@ -2,10 +2,10 @@ slug: js/object-cloning name: JavaScript Object Cloning featured: true snippetIds: - - articles/s/javascript-shallow-deep-clone - - js/s/shallow-clone - - js/s/deep-clone - - articles/s/javascript-copy-array + - js/s/shallow-deep-clone + - js/s/shallow-clone-object + - js/s/deep-clone-object + - js/s/copy-array splash: coffee-phone-tray.png description: >- JavaScript objects and arrays are a little tricky to clone. Luckily, this diff --git a/collections/js/object-key-selection.yaml b/collections/js/object-key-selection.yaml index 2d4567899..63615d4e0 100644 --- a/collections/js/object-key-selection.yaml +++ b/collections/js/object-key-selection.yaml @@ -2,10 +2,10 @@ slug: js/object-key-selection name: JavaScript Object Key Selection featured: true snippetIds: - - js/s/pick - - js/s/omit - - js/s/pick-by - - js/s/omit-by + - js/s/pick-object-keys + - js/s/omit-object-keys + - js/s/pick-matching-object-keys + - js/s/omit-matching-object-keys splash: succulent-cluster.png description: >- Sometimes, JavaScript objects come with a lot of keys and you only need a few diff --git a/collections/js/object-key-transformations.yaml b/collections/js/object-key-transformations.yaml index 6a431da3c..3d9513862 100644 --- a/collections/js/object-key-transformations.yaml +++ b/collections/js/object-key-transformations.yaml @@ -4,10 +4,10 @@ featured: true snippetIds: - js/s/lowerize - js/s/upperize - - js/s/map-keys - - js/s/rename-keys - - js/s/deep-map-keys - - js/s/symbolize-keys + - js/s/map-object-keys + - js/s/rename-object-keys + - js/s/deep-map-object-keys + - js/s/symbolize-object-keys splash: plant-window.png description: >- Sometimes, object keys aren't exactly what you want them to be. Luckily, this diff --git a/collections/js/performance.yaml b/collections/js/performance.yaml index f567fd988..714c7b463 100644 --- a/collections/js/performance.yaml +++ b/collections/js/performance.yaml @@ -2,16 +2,16 @@ slug: js/performance name: JavaScript Performance Optimization featured: true snippetIds: - - articles/s/javascript-store-dom-items - - articles/s/passive-scroll-listener-performance - - articles/s/js-textcontent-or-innertext - - articles/s/javascript-memoization - - articles/s/js-array-filtering-tips - - articles/s/js-fast-remove-array-element - - articles/s/code-anatomy-optimizing-recursion - - articles/s/javascript-switch-object - - articles/s/js-dynamic-properties-are-slow - - articles/s/big-o-cheatsheet + - js/s/store-dom-items + - js/s/passive-scroll-listener-performance + - js/s/textcontent-or-innertext + - js/s/memoization + - js/s/array-filtering-tips + - js/s/fast-remove-array-element + - js/s/code-anatomy-optimizing-recursion + - js/s/switch-object + - js/s/dynamic-properties-are-slow + - js/s/big-o-cheatsheet splash: do-more-computer.png description: >- Enhance your website's performance with our collection of tips and tricks on diff --git a/collections/js/promises.yaml b/collections/js/promises.yaml index 5c7867784..544d56334 100644 --- a/collections/js/promises.yaml +++ b/collections/js/promises.yaml @@ -2,12 +2,12 @@ slug: js/promises name: JavaScript Promises featured: true snippetIds: - - articles/s/javascript-promises - - articles/s/async-javascript-cheatsheet - - articles/s/javascript-sync-async - - articles/s/javascript-promise-then-catch - - articles/s/javascript-promise-then-finally - - articles/s/javascript-await-timeout + - js/s/promises + - js/s/async-cheatsheet + - js/s/sync-async + - js/s/promise-then-catch + - js/s/promise-then-finally + - js/s/await-timeout - js/s/debounce-promise - js/s/run-promises-in-series splash: blue-computer.png diff --git a/collections/js/proxy.yaml b/collections/js/proxy.yaml index 6d78a8760..4a5076282 100644 --- a/collections/js/proxy.yaml +++ b/collections/js/proxy.yaml @@ -2,15 +2,15 @@ slug: js/proxy name: JavaScript Proxy featured: true snippetIds: - - articles/s/js-proxy-introduction - - articles/s/js-dynamic-getter-setter-proxy - - articles/s/js-immutable-object-proxy - - articles/s/javascript-singleton-proxy - - articles/s/js-dynamic-getter-chain-proxy - - articles/s/javascript-object-array-proxy - - articles/s/js-proxy-array-negative-index - - articles/s/js-cannot-extend-proxy-object - - articles/s/js-typecheck-proxy + - js/s/proxy-introduction + - js/s/dynamic-getter-setter-proxy + - js/s/immutable-object-proxy + - js/s/singleton-proxy + - js/s/dynamic-getter-chain-proxy + - js/s/object-array-proxy + - js/s/proxy-array-negative-index + - js/s/cannot-extend-proxy-object + - js/s/typecheck-proxy splash: laptop-coffee.png description: >- The JavaScript Proxy object can be a very powerful tool to extend the diff --git a/collections/js/random-value-generators.yaml b/collections/js/random-value-generators.yaml index 57f9a8ab7..ccfb5c782 100644 --- a/collections/js/random-value-generators.yaml +++ b/collections/js/random-value-generators.yaml @@ -4,8 +4,8 @@ featured: true snippetIds: - js/s/random-number-in-range - js/s/random-integer-in-range - - js/s/random-int-array-in-range - - js/s/random-alpha-numeric + - js/s/random-integer-array-in-range + - js/s/random-alphanumeric - js/s/random-boolean - js/s/random-hex-color-code - js/s/random-gauss diff --git a/collections/js/url.yaml b/collections/js/url.yaml index b6faa2737..2d2a5f9c9 100644 --- a/collections/js/url.yaml +++ b/collections/js/url.yaml @@ -2,19 +2,19 @@ slug: js/url name: URLs in JavaScript featured: true snippetIds: - - articles/s/javascript-modify-url-without-reload - - articles/s/js-construct-url - - articles/s/js-edit-url-params - - articles/s/javascript-reload-page - - articles/s/js-window-location-cheatsheet + - js/s/modify-url-without-reload + - js/s/construct-url + - js/s/edit-url-params + - js/s/reload-page + - js/s/window-location-cheatsheet - js/s/current-url - js/s/https-redirect - js/s/get-url-parameters - js/s/get-base-url - - js/s/redirect + - js/s/redirect-to-url - js/s/is-absolute-url - js/s/is-same-origin - - js/s/url-join + - js/s/join-url-segments splash: pots-and-plants.png description: >- URLs are an integral part of the web, which makes working with them an diff --git a/collections/js/web-storage-essentials.yaml b/collections/js/web-storage-essentials.yaml index ba8786079..82f1dc013 100644 --- a/collections/js/web-storage-essentials.yaml +++ b/collections/js/web-storage-essentials.yaml @@ -2,7 +2,7 @@ slug: js/web-storage-essentials name: Web Storage Essentials featured: true snippetIds: - - articles/s/cookies-local-storage-session + - js/s/cookies-local-storage-session - js/s/parse-cookie - js/s/serialize-cookie - js/s/is-local-storage-enabled diff --git a/collections/main-listing.yaml b/collections/main-listing.yaml index a91630471..8c41da0a3 100644 --- a/collections/main-listing.yaml +++ b/collections/main-listing.yaml @@ -1,4 +1,4 @@ -slug: list +slug: snippets name: Code Snippets featured: false splash: laptop-plant.png diff --git a/collections/react/rendering.yaml b/collections/react/rendering.yaml index e687ca814..7c8cbf059 100644 --- a/collections/react/rendering.yaml +++ b/collections/react/rendering.yaml @@ -4,9 +4,9 @@ miniName: Rendering parent: react featured: true snippetIds: - - articles/s/react-rendering-basics - - articles/s/react-rendering-optimization - - articles/s/react-rendering-state + - react/s/rendering-basics + - react/s/rendering-optimization + - react/s/rendering-state splash: glasses-comic.png description: >- Understanding of the rendering process is a crucial piece of knowledge when diff --git a/collections/react/testing.yaml b/collections/react/testing.yaml index a31032b98..f500e9a85 100644 --- a/collections/react/testing.yaml +++ b/collections/react/testing.yaml @@ -4,10 +4,10 @@ shortName: Testing parent: react featured: true snippetIds: - - articles/s/testing-stateful-ui-components - - articles/s/testing-async-react-components - - articles/s/testing-react-portals - - articles/s/testing-redux-connected-components + - react/s/testing-stateful-ui-components + - react/s/testing-async-components + - react/s/testing-portals + - react/s/testing-redux-connected-components splash: headphones.png description: >- Testing React can be challenging, both in terms of figuring out the correct diff --git a/snippets/articles/s/8-tips-for-accessible-websites.md b/snippets/articles/s/8-tips-for-accessible-websites.md index 74c291d3a..ec2e02dc7 100644 --- a/snippets/articles/s/8-tips-for-accessible-websites.md +++ b/snippets/articles/s/8-tips-for-accessible-websites.md @@ -2,7 +2,7 @@ title: 8 tips for accessible websites shortTitle: Accessibility tips type: story -language: javascript +language: html tags: [accessibility,webdev] author: chalarangelo cover: accessibility diff --git a/snippets/articles/s/javascript-sleep.md b/snippets/articles/s/javascript-sleep.md deleted file mode 100644 index 635fb44bc..000000000 --- a/snippets/articles/s/javascript-sleep.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: How can I implement a sleep function in JavaScript? -shortTitle: Sleep function -type: question -language: javascript -tags: [date,promise] -author: chalarangelo -cover: sleepy-cat -excerpt: Learn all the different ways you can implement a `sleep()` function in JavaScript. -dateModified: 2021-11-06T20:51:47+03:00 ---- - -JavaScript does not come with a `sleep()` function out of the box. That's probably a good idea considering the environments where it runs and the trouble it could cause if used incorrectly. The closest equivalent is the `setTimeout()` function, but there are other, less common ways to implement a function that will pause execution for a specified amount of time. - -### setTimeout - -JavaScript's `setTimeout()` sets a timer which executes some code once the timer expires. Only the code inside the `setTimeout()` callback will execute after the timer expires. This can lead to nesting issues, as well as code executing out of order if you are not careful. - -```js -const printNums = () => { - console.log(1); - setTimeout(() => console.log(2), 500); - console.log(3); -}; - -printNums(); // Logs: 1, 3, 2 (2 logs after 500ms) -``` - -### Synchronous version - -While strongly discouraged, `Date.prototype.getTime()` can be used inside a `while` loop to pause execution for a set amount of time. You can easily define a synchronous `sleep()` function like this: - -```js -const sleepSync = (ms) => { - const end = new Date().getTime() + ms; - while (new Date().getTime() < end) { /* do nothing */ } -} - -const printNums = () => { - console.log(1); - sleepSync(500); - console.log(2); - console.log(3); -}; - -printNums(); // Logs: 1, 2, 3 (2 and 3 log after 500ms) -``` - -### Asynchronous version - -A less intrusive way to go about implementing a `sleep()` function is to utilize the `async` and `await` keywords added in JavaScript ES6, a `Promise` and `setTimeout()`. Note that the resulting function must be executed in an `async` function and has to be called with `await`: - -```js -const sleep = (ms) => - new Promise(resolve => setTimeout(resolve, ms)); - -const printNums = async() => { - console.log(1); - await sleep(500); - console.log(2); - console.log(3); -}; - -printNums(); // Logs: 1, 2, 3 (2 and 3 log after 500ms) -``` diff --git a/snippets/articles/s/25-css-gradients.md b/snippets/css/s/25-css-gradients.md similarity index 100% rename from snippets/articles/s/25-css-gradients.md rename to snippets/css/s/25-css-gradients.md diff --git a/snippets/articles/s/css-centering.md b/snippets/css/s/centering.md similarity index 100% rename from snippets/articles/s/css-centering.md rename to snippets/css/s/centering.md diff --git a/snippets/articles/s/css-clamp.md b/snippets/css/s/clamp.md similarity index 100% rename from snippets/articles/s/css-clamp.md rename to snippets/css/s/clamp.md diff --git a/snippets/articles/s/css-code-reviews.md b/snippets/css/s/code-reviews.md similarity index 100% rename from snippets/articles/s/css-code-reviews.md rename to snippets/css/s/code-reviews.md diff --git a/snippets/articles/s/css-current-color.md b/snippets/css/s/current-color.md similarity index 100% rename from snippets/articles/s/css-current-color.md rename to snippets/css/s/current-color.md diff --git a/snippets/articles/s/css-easing-variables.md b/snippets/css/s/easing-variables.md similarity index 100% rename from snippets/articles/s/css-easing-variables.md rename to snippets/css/s/easing-variables.md diff --git a/snippets/articles/s/flexbox-cheatsheet.md b/snippets/css/s/flexbox-cheatsheet.md similarity index 100% rename from snippets/articles/s/flexbox-cheatsheet.md rename to snippets/css/s/flexbox-cheatsheet.md diff --git a/snippets/articles/s/css-footer-at-the-bottom.md b/snippets/css/s/footer-at-the-bottom.md similarity index 100% rename from snippets/articles/s/css-footer-at-the-bottom.md rename to snippets/css/s/footer-at-the-bottom.md diff --git a/snippets/articles/s/css-inherited-properties-cheatsheet.md b/snippets/css/s/inherited-properties-cheatsheet.md similarity index 100% rename from snippets/articles/s/css-inherited-properties-cheatsheet.md rename to snippets/css/s/inherited-properties-cheatsheet.md diff --git a/snippets/articles/s/css-nested-border-radius.md b/snippets/css/s/nested-border-radius.md similarity index 100% rename from snippets/articles/s/css-nested-border-radius.md rename to snippets/css/s/nested-border-radius.md diff --git a/snippets/articles/s/perfect-css-transition-duration.md b/snippets/css/s/perfect-transition-duration.md similarity index 100% rename from snippets/articles/s/perfect-css-transition-duration.md rename to snippets/css/s/perfect-transition-duration.md diff --git a/snippets/articles/s/css-print-stylesheet.md b/snippets/css/s/print-stylesheet.md similarity index 100% rename from snippets/articles/s/css-print-stylesheet.md rename to snippets/css/s/print-stylesheet.md diff --git a/snippets/articles/s/css-pseudo-classes.md b/snippets/css/s/pseudo-classes.md similarity index 100% rename from snippets/articles/s/css-pseudo-classes.md rename to snippets/css/s/pseudo-classes.md diff --git a/snippets/articles/s/css-reset.md b/snippets/css/s/reset.md similarity index 100% rename from snippets/articles/s/css-reset.md rename to snippets/css/s/reset.md diff --git a/snippets/articles/s/responsive-favicon-dark-mode.md b/snippets/css/s/responsive-favicon-dark-mode.md similarity index 100% rename from snippets/articles/s/responsive-favicon-dark-mode.md rename to snippets/css/s/responsive-favicon-dark-mode.md diff --git a/snippets/articles/s/css-root-vs-html.md b/snippets/css/s/root-vs-html.md similarity index 100% rename from snippets/articles/s/css-root-vs-html.md rename to snippets/css/s/root-vs-html.md diff --git a/snippets/articles/s/css-select-any-link.md b/snippets/css/s/select-any-link.md similarity index 100% rename from snippets/articles/s/css-select-any-link.md rename to snippets/css/s/select-any-link.md diff --git a/snippets/articles/s/css-style-default-links.md b/snippets/css/s/style-default-links.md similarity index 91% rename from snippets/articles/s/css-style-default-links.md rename to snippets/css/s/style-default-links.md index f7e4000dc..7f51a897c 100644 --- a/snippets/articles/s/css-style-default-links.md +++ b/snippets/css/s/style-default-links.md @@ -19,4 +19,4 @@ a[href]:not([class]) { } ``` -As a bonus tip, you can use [the previous tip about selecting any link](/articles/s/css-select-any-link) to further enhance this solution. +As a bonus tip, you can use [the previous tip about selecting any link](/css/s/select-any-link) to further enhance this solution. diff --git a/snippets/articles/s/typographic-scale-basics.md b/snippets/css/s/typographic-scale-basics.md similarity index 100% rename from snippets/articles/s/typographic-scale-basics.md rename to snippets/css/s/typographic-scale-basics.md diff --git a/snippets/articles/s/css-unitless-line-height.md b/snippets/css/s/unitless-line-height.md similarity index 100% rename from snippets/articles/s/css-unitless-line-height.md rename to snippets/css/s/unitless-line-height.md diff --git a/snippets/articles/s/css-units-cheatsheet.md b/snippets/css/s/units-cheatsheet.md similarity index 100% rename from snippets/articles/s/css-units-cheatsheet.md rename to snippets/css/s/units-cheatsheet.md diff --git a/snippets/articles/s/css-variables.md b/snippets/css/s/variables.md similarity index 100% rename from snippets/articles/s/css-variables.md rename to snippets/css/s/variables.md diff --git a/snippets/articles/s/5-tips-for-better-pull-requests.md b/snippets/git/s/5-tips-for-better-pull-requests.md similarity index 100% rename from snippets/articles/s/5-tips-for-better-pull-requests.md rename to snippets/git/s/5-tips-for-better-pull-requests.md diff --git a/snippets/articles/s/git-aliases.md b/snippets/git/s/aliases.md similarity index 100% rename from snippets/articles/s/git-aliases.md rename to snippets/git/s/aliases.md diff --git a/snippets/articles/s/git-commit-different-date.md b/snippets/git/s/commit-different-date.md similarity index 100% rename from snippets/articles/s/git-commit-different-date.md rename to snippets/git/s/commit-different-date.md diff --git a/snippets/articles/s/git-fast-forward.md b/snippets/git/s/fast-forward.md similarity index 100% rename from snippets/articles/s/git-fast-forward.md rename to snippets/git/s/fast-forward.md diff --git a/snippets/articles/s/github-co-authors.md b/snippets/git/s/github-co-authors.md similarity index 100% rename from snippets/articles/s/github-co-authors.md rename to snippets/git/s/github-co-authors.md diff --git a/snippets/articles/s/10-vs-code-extensions-for-js-developers.md b/snippets/js/s/10-vs-code-extensions-for-js-developers.md similarity index 100% rename from snippets/articles/s/10-vs-code-extensions-for-js-developers.md rename to snippets/js/s/10-vs-code-extensions-for-js-developers.md diff --git a/snippets/articles/s/4-javascript-array-methods.md b/snippets/js/s/4-array-methods.md similarity index 100% rename from snippets/articles/s/4-javascript-array-methods.md rename to snippets/js/s/4-array-methods.md diff --git a/snippets/articles/s/6-javascript-regexp-tricks.md b/snippets/js/s/6-regexp-tricks.md similarity index 100% rename from snippets/articles/s/6-javascript-regexp-tricks.md rename to snippets/js/s/6-regexp-tricks.md diff --git a/snippets/articles/s/js-abort-fetch.md b/snippets/js/s/abort-fetch.md similarity index 100% rename from snippets/articles/s/js-abort-fetch.md rename to snippets/js/s/abort-fetch.md diff --git a/snippets/js/s/add-class.md b/snippets/js/s/add-class-to-html-element.md similarity index 100% rename from snippets/js/s/add-class.md rename to snippets/js/s/add-class-to-html-element.md diff --git a/snippets/js/s/on.md b/snippets/js/s/add-event-listener.md similarity index 100% rename from snippets/js/s/on.md rename to snippets/js/s/add-event-listener.md diff --git a/snippets/articles/s/javascript-add-key-value-pair-to-object.md b/snippets/js/s/add-key-value-pair-to-object.md similarity index 100% rename from snippets/articles/s/javascript-add-key-value-pair-to-object.md rename to snippets/js/s/add-key-value-pair-to-object.md diff --git a/snippets/js/s/add-multiple-events.md b/snippets/js/s/add-multiple-event-listeners.md similarity index 100% rename from snippets/js/s/add-multiple-events.md rename to snippets/js/s/add-multiple-event-listeners.md diff --git a/snippets/js/s/add-styles.md b/snippets/js/s/add-styles-to-html-element.md similarity index 100% rename from snippets/js/s/add-styles.md rename to snippets/js/s/add-styles-to-html-element.md diff --git a/snippets/js/s/add-week-days.md b/snippets/js/s/add-weekdays-to-date.md similarity index 100% rename from snippets/js/s/add-week-days.md rename to snippets/js/s/add-weekdays-to-date.md diff --git a/snippets/js/s/none.md b/snippets/js/s/all-array-elements-are-falsy.md similarity index 100% rename from snippets/js/s/none.md rename to snippets/js/s/all-array-elements-are-falsy.md diff --git a/snippets/js/s/all.md b/snippets/js/s/all-array-elements-are-truthy.md similarity index 100% rename from snippets/js/s/all.md rename to snippets/js/s/all-array-elements-are-truthy.md diff --git a/snippets/js/s/any.md b/snippets/js/s/any-array-element-is-truthy.md similarity index 100% rename from snippets/js/s/any.md rename to snippets/js/s/any-array-element-is-truthy.md diff --git a/snippets/articles/s/js-append-elements-to-array.md b/snippets/js/s/append-elements-to-array.md similarity index 100% rename from snippets/articles/s/js-append-elements-to-array.md rename to snippets/js/s/append-elements-to-array.md diff --git a/snippets/js/s/partial-right.md b/snippets/js/s/append-function-arguments.md similarity index 100% rename from snippets/js/s/partial-right.md rename to snippets/js/s/append-function-arguments.md diff --git a/snippets/js/s/coalesce-factory.md b/snippets/js/s/argument-coalescing-factory.md similarity index 100% rename from snippets/js/s/coalesce-factory.md rename to snippets/js/s/argument-coalescing-factory.md diff --git a/snippets/js/s/coalesce.md b/snippets/js/s/argument-coalescing.md similarity index 100% rename from snippets/js/s/coalesce.md rename to snippets/js/s/argument-coalescing.md diff --git a/snippets/articles/s/javascript-array-comparison.md b/snippets/js/s/array-comparison.md similarity index 100% rename from snippets/articles/s/javascript-array-comparison.md rename to snippets/js/s/array-comparison.md diff --git a/snippets/js/s/difference.md b/snippets/js/s/array-difference.md similarity index 100% rename from snippets/js/s/difference.md rename to snippets/js/s/array-difference.md diff --git a/snippets/js/s/all-equal.md b/snippets/js/s/array-element-equality.md similarity index 100% rename from snippets/js/s/all-equal.md rename to snippets/js/s/array-element-equality.md diff --git a/snippets/js/s/all-unique.md b/snippets/js/s/array-element-uniqueness.md similarity index 100% rename from snippets/js/s/all-unique.md rename to snippets/js/s/array-element-uniqueness.md diff --git a/snippets/articles/s/js-array-filtering-tips.md b/snippets/js/s/array-filtering-tips.md similarity index 100% rename from snippets/articles/s/js-array-filtering-tips.md rename to snippets/js/s/array-filtering-tips.md diff --git a/snippets/js/s/has-duplicates.md b/snippets/js/s/array-has-duplicates.md similarity index 100% rename from snippets/js/s/has-duplicates.md rename to snippets/js/s/array-has-duplicates.md diff --git a/snippets/js/s/has-many.md b/snippets/js/s/array-has-many-matches.md similarity index 100% rename from snippets/js/s/has-many.md rename to snippets/js/s/array-has-many-matches.md diff --git a/snippets/js/s/has-one.md b/snippets/js/s/array-has-only-one-match.md similarity index 100% rename from snippets/js/s/has-one.md rename to snippets/js/s/array-has-only-one-match.md diff --git a/snippets/js/s/head.md b/snippets/js/s/array-head.md similarity index 100% rename from snippets/js/s/head.md rename to snippets/js/s/array-head.md diff --git a/snippets/js/s/includes-all.md b/snippets/js/s/array-includes-all-values.md similarity index 100% rename from snippets/js/s/includes-all.md rename to snippets/js/s/array-includes-all-values.md diff --git a/snippets/js/s/includes-any.md b/snippets/js/s/array-includes-any-values.md similarity index 100% rename from snippets/js/s/includes-any.md rename to snippets/js/s/array-includes-any-values.md diff --git a/snippets/articles/s/javascript-array-includes-value.md b/snippets/js/s/array-includes-value.md similarity index 85% rename from snippets/articles/s/javascript-array-includes-value.md rename to snippets/js/s/array-includes-value.md index 7ceb55ac4..9a65658e3 100644 --- a/snippets/articles/s/javascript-array-includes-value.md +++ b/snippets/js/s/array-includes-value.md @@ -24,7 +24,7 @@ array.includes(3, 3); // false ### Objects -Unlike primitive values, you can't use `Array.prototype.includes()` to check if an array includes an object. This comes down to how JavaScript compares values and the fact that [objects are reference types](/articles/s/javascript-pass-by-reference-or-pass-by-value). I highly recommend reading the previous article about [object comparison](/articles/s/javascript-object-comparison), as I won't be going into detail on how to compare objects here. +Unlike primitive values, you can't use `Array.prototype.includes()` to check if an array includes an object. This comes down to how JavaScript compares values and the fact that [objects are reference types](/js/s/pass-by-reference-or-pass-by-value). I highly recommend reading the previous article about [object comparison](/js/s/object-comparison), as I won't be going into detail on how to compare objects here. Due to this difference between primitive values and objects, you can't use `Array.prototype.includes()` to check if an array includes an object. However, provided you implement a [deep equality function](/js/s/equals), you can use `Array.prototype.some()` to check if any object matches the shape of another object. diff --git a/snippets/articles/s/js-array-initialization.md b/snippets/js/s/array-initialization.md similarity index 100% rename from snippets/articles/s/js-array-initialization.md rename to snippets/js/s/array-initialization.md diff --git a/snippets/js/s/intersection.md b/snippets/js/s/array-intersection.md similarity index 100% rename from snippets/js/s/intersection.md rename to snippets/js/s/array-intersection.md diff --git a/snippets/js/s/is-contained-in.md b/snippets/js/s/array-is-contained-in.md similarity index 100% rename from snippets/js/s/is-contained-in.md rename to snippets/js/s/array-is-contained-in.md diff --git a/snippets/js/s/is-sorted.md b/snippets/js/s/array-is-sorted.md similarity index 100% rename from snippets/js/s/is-sorted.md rename to snippets/js/s/array-is-sorted.md diff --git a/snippets/articles/s/js-array-map-vs-foreach.md b/snippets/js/s/array-map-vs-foreach.md similarity index 92% rename from snippets/articles/s/js-array-map-vs-foreach.md rename to snippets/js/s/array-map-vs-foreach.md index dbe174048..d72bf7a59 100644 --- a/snippets/articles/s/js-array-map-vs-foreach.md +++ b/snippets/js/s/array-map-vs-foreach.md @@ -28,4 +28,4 @@ const doubledNumbers = numbers.map(num => num * 2); The way I like to distinguish them is by remembering that `Array.prototype.map()` represents a **transformation**, whereas `Array.prototype.forEach()` represents an **iteration**. Hopefully, one of these explanations will click for you and help you remember the difference between the two. -As a closing note, I would like to remind you that the humble `for` loop can be more efficient in some cases, such as [breaking out of a loop early](/articles/s/javascript-for-loop-early-break). Always pick the right tool for the job, as ES6 has a method for almost every use case. +As a closing note, I would like to remind you that the humble `for` loop can be more efficient in some cases, such as [breaking out of a loop early](/js/s/for-loop-early-break). Always pick the right tool for the job, as ES6 has a method for almost every use case. diff --git a/snippets/articles/s/js-array-min-max.md b/snippets/js/s/array-min-max.md similarity index 100% rename from snippets/articles/s/js-array-min-max.md rename to snippets/js/s/array-min-max.md diff --git a/snippets/js/s/permutations.md b/snippets/js/s/array-permutations.md similarity index 100% rename from snippets/js/s/permutations.md rename to snippets/js/s/array-permutations.md diff --git a/snippets/js/s/ranking.md b/snippets/js/s/array-ranking.md similarity index 100% rename from snippets/js/s/ranking.md rename to snippets/js/s/array-ranking.md diff --git a/snippets/js/s/sample.md b/snippets/js/s/array-sample.md similarity index 100% rename from snippets/js/s/sample.md rename to snippets/js/s/array-sample.md diff --git a/snippets/js/s/similarity.md b/snippets/js/s/array-similarity.md similarity index 100% rename from snippets/js/s/similarity.md rename to snippets/js/s/array-similarity.md diff --git a/snippets/articles/s/js-array-sorting-shorthand.md b/snippets/js/s/array-sorting-shorthand.md similarity index 100% rename from snippets/articles/s/js-array-sorting-shorthand.md rename to snippets/js/s/array-sorting-shorthand.md diff --git a/snippets/js/s/symmetric-difference.md b/snippets/js/s/array-symmetric-difference.md similarity index 100% rename from snippets/js/s/symmetric-difference.md rename to snippets/js/s/array-symmetric-difference.md diff --git a/snippets/js/s/tail.md b/snippets/js/s/array-tail.md similarity index 100% rename from snippets/js/s/tail.md rename to snippets/js/s/array-tail.md diff --git a/snippets/js/s/to-identity-object.md b/snippets/js/s/array-to-identity-object.md similarity index 100% rename from snippets/js/s/to-identity-object.md rename to snippets/js/s/array-to-identity-object.md diff --git a/snippets/js/s/index-on.md b/snippets/js/s/array-to-object-based-on-key.md similarity index 100% rename from snippets/js/s/index-on.md rename to snippets/js/s/array-to-object-based-on-key.md diff --git a/snippets/js/s/union.md b/snippets/js/s/array-union.md similarity index 100% rename from snippets/js/s/union.md rename to snippets/js/s/array-union.md diff --git a/snippets/js/s/unique-symmetric-difference.md b/snippets/js/s/array-unique-symmetric-difference.md similarity index 100% rename from snippets/js/s/unique-symmetric-difference.md rename to snippets/js/s/array-unique-symmetric-difference.md diff --git a/snippets/js/s/initial.md b/snippets/js/s/array-without-last-element.md similarity index 100% rename from snippets/js/s/initial.md rename to snippets/js/s/array-without-last-element.md diff --git a/snippets/js/s/have-same-contents.md b/snippets/js/s/arrays-have-same-contents.md similarity index 100% rename from snippets/js/s/have-same-contents.md rename to snippets/js/s/arrays-have-same-contents.md diff --git a/snippets/js/s/intersects.md b/snippets/js/s/arrays-intersect.md similarity index 100% rename from snippets/js/s/intersects.md rename to snippets/js/s/arrays-intersect.md diff --git a/snippets/js/s/find-consecutive.md b/snippets/js/s/arrays-of-consecutive-elements.md similarity index 100% rename from snippets/js/s/find-consecutive.md rename to snippets/js/s/arrays-of-consecutive-elements.md diff --git a/snippets/articles/s/javascript-arrow-function-event-listeners.md b/snippets/js/s/arrow-function-event-listeners.md similarity index 100% rename from snippets/articles/s/javascript-arrow-function-event-listeners.md rename to snippets/js/s/arrow-function-event-listeners.md diff --git a/snippets/articles/s/javascript-arrow-functions.md b/snippets/js/s/arrow-functions.md similarity index 100% rename from snippets/articles/s/javascript-arrow-functions.md rename to snippets/js/s/arrow-functions.md diff --git a/snippets/articles/s/javascript-arrow-regular-function-differences.md b/snippets/js/s/arrow-regular-function-differences.md similarity index 100% rename from snippets/articles/s/javascript-arrow-regular-function-differences.md rename to snippets/js/s/arrow-regular-function-differences.md diff --git a/snippets/js/s/assert-valid-keys.md b/snippets/js/s/assert-object-key-validity.md similarity index 100% rename from snippets/js/s/assert-valid-keys.md rename to snippets/js/s/assert-object-key-validity.md diff --git a/snippets/articles/s/javascript-async-array-loops.md b/snippets/js/s/async-array-loops.md similarity index 100% rename from snippets/articles/s/javascript-async-array-loops.md rename to snippets/js/s/async-array-loops.md diff --git a/snippets/articles/s/async-javascript-cheatsheet.md b/snippets/js/s/async-cheatsheet.md similarity index 100% rename from snippets/articles/s/async-javascript-cheatsheet.md rename to snippets/js/s/async-cheatsheet.md diff --git a/snippets/articles/s/js-async-defer.md b/snippets/js/s/async-defer.md similarity index 100% rename from snippets/articles/s/js-async-defer.md rename to snippets/js/s/async-defer.md diff --git a/snippets/js/s/attempt.md b/snippets/js/s/attempt-invoking-function.md similarity index 100% rename from snippets/js/s/attempt.md rename to snippets/js/s/attempt-invoking-function.md diff --git a/snippets/js/s/average.md b/snippets/js/s/average-of-numbers.md similarity index 100% rename from snippets/js/s/average.md rename to snippets/js/s/average-of-numbers.md diff --git a/snippets/articles/s/javascript-await-timeout.md b/snippets/js/s/await-timeout.md similarity index 100% rename from snippets/articles/s/javascript-await-timeout.md rename to snippets/js/s/await-timeout.md diff --git a/snippets/js/s/bifurcate-by.md b/snippets/js/s/bifurcate-array-based-on-function.md similarity index 100% rename from snippets/js/s/bifurcate-by.md rename to snippets/js/s/bifurcate-array-based-on-function.md diff --git a/snippets/js/s/bifurcate.md b/snippets/js/s/bifurcate-array-based-on-values.md similarity index 100% rename from snippets/js/s/bifurcate.md rename to snippets/js/s/bifurcate-array-based-on-values.md diff --git a/snippets/articles/s/big-o-cheatsheet.md b/snippets/js/s/big-o-cheatsheet.md similarity index 71% rename from snippets/articles/s/big-o-cheatsheet.md rename to snippets/js/s/big-o-cheatsheet.md index efc945464..75a38630d 100644 --- a/snippets/articles/s/big-o-cheatsheet.md +++ b/snippets/js/s/big-o-cheatsheet.md @@ -27,27 +27,27 @@ Different data structures have different time complexities for the same operatio | Data Structure | Access | Search | Insertion | Deletion | | --- | --- | --- | --- | --- | -| [**Array**](/articles/s/js-native-data-structures) | Θ(1) | Θ(n) | Θ(n) | Θ(n) | -| [**Queue**](/articles/s/js-data-structures-queue) | Θ(n) | Θ(n) | Θ(1) | Θ(1) | -| [**Stack**](/articles/s/js-data-structures-stack) | Θ(n) | Θ(n) | Θ(1) | Θ(1) | -| [**Linked List**](/articles/s/js-data-structures-linked-list) | Θ(n) | Θ(n) | Θ(1) | Θ(1) | -| [**Doubly Linked List**](/articles/s/js-data-structures-doubly-linked-list) | Θ(n) | Θ(n) | Θ(1) | Θ(1) | +| [**Array**](/js/s/native-data-structures) | Θ(1) | Θ(n) | Θ(n) | Θ(n) | +| [**Queue**](/js/s/data-structures-queue) | Θ(n) | Θ(n) | Θ(1) | Θ(1) | +| [**Stack**](/js/s/data-structures-stack) | Θ(n) | Θ(n) | Θ(1) | Θ(1) | +| [**Linked List**](/js/s/data-structures-linked-list) | Θ(n) | Θ(n) | Θ(1) | Θ(1) | +| [**Doubly Linked List**](/js/s/data-structures-doubly-linked-list) | Θ(n) | Θ(n) | Θ(1) | Θ(1) | | **Skip List** | Θ(log n) | Θ(log n) | Θ(log n) | Θ(log n) | | **Hash Table** | N/A | Θ(1) | Θ(1) | Θ(1) | -| [**Binary Search Tree**](/articles/s/js-data-structures-binary-search-tree) | Θ(log n) | Θ(log n) | Θ(log n) | Θ(log n) | +| [**Binary Search Tree**](/js/s/data-structures-binary-search-tree) | Θ(log n) | Θ(log n) | Θ(log n) | Θ(log n) | #### Worst time complexity | Data Structure | Access | Search | Insertion | Deletion | | --- | --- | --- | --- | --- | -| [**Array**](/articles/s/js-native-data-structures) | O(1) | O(n) | O(n) | O(n) | -| [**Queue**](/articles/s/js-data-structures-queue) | O(n) | O(n) | O(1) | O(1) | -| [**Stack**](/articles/s/js-data-structures-stack) | O(n) | O(n) | O(1) | O(1) | -| [**Linked List**](/articles/s/js-data-structures-linked-list) | O(n) | O(n) | O(1) | O(1) | -| [**Doubly Linked List**](/articles/s/js-data-structures-doubly-linked-list) | O(n) | O(n) | O(1) | O(1) | +| [**Array**](/js/s/native-data-structures) | O(1) | O(n) | O(n) | O(n) | +| [**Queue**](/js/s/data-structures-queue) | O(n) | O(n) | O(1) | O(1) | +| [**Stack**](/js/s/data-structures-stack) | O(n) | O(n) | O(1) | O(1) | +| [**Linked List**](/js/s/data-structures-linked-list) | O(n) | O(n) | O(1) | O(1) | +| [**Doubly Linked List**](/js/s/data-structures-doubly-linked-list) | O(n) | O(n) | O(1) | O(1) | | **Skip List** | O(n) | O(n) | O(n) | O(n) | | **Hash Table** | N/A | O(n) | O(n) | O(n) | -| [**Binary Search Tree**](/articles/s/js-data-structures-binary-search-tree) | O(n) | O(n) | O(n) | O(n) | +| [**Binary Search Tree**](/js/s/data-structures-binary-search-tree) | O(n) | O(n) | O(n) | O(n) | ### Array sorting algorithms diff --git a/snippets/js/s/binary.md b/snippets/js/s/binary-function-arity.md similarity index 100% rename from snippets/js/s/binary.md rename to snippets/js/s/binary-function-arity.md diff --git a/snippets/js/s/bind.md b/snippets/js/s/bind-function-context.md similarity index 100% rename from snippets/js/s/bind.md rename to snippets/js/s/bind-function-context.md diff --git a/snippets/js/s/bind-key.md b/snippets/js/s/bind-object-method.md similarity index 100% rename from snippets/js/s/bind-key.md rename to snippets/js/s/bind-object-method.md diff --git a/snippets/js/s/bind-all.md b/snippets/js/s/bind-object-methods.md similarity index 100% rename from snippets/js/s/bind-all.md rename to snippets/js/s/bind-object-methods.md diff --git a/snippets/articles/s/javascript-blank-value.md b/snippets/js/s/blank-value.md similarity index 100% rename from snippets/articles/s/javascript-blank-value.md rename to snippets/js/s/blank-value.md diff --git a/snippets/articles/s/javascript-boolean-function.md b/snippets/js/s/boolean-function.md similarity index 100% rename from snippets/articles/s/javascript-boolean-function.md rename to snippets/js/s/boolean-function.md diff --git a/snippets/articles/s/javascript-boolean-trap.md b/snippets/js/s/boolean-trap.md similarity index 100% rename from snippets/articles/s/javascript-boolean-trap.md rename to snippets/js/s/boolean-trap.md diff --git a/snippets/js/s/once.md b/snippets/js/s/call-function-once.md similarity index 100% rename from snippets/js/s/once.md rename to snippets/js/s/call-function-once.md diff --git a/snippets/js/s/call.md b/snippets/js/s/call-functions-with-context.md similarity index 100% rename from snippets/js/s/call.md rename to snippets/js/s/call-functions-with-context.md diff --git a/snippets/articles/s/javascript-callbacks.md b/snippets/js/s/callback-pitfalls.md similarity index 100% rename from snippets/articles/s/javascript-callbacks.md rename to snippets/js/s/callback-pitfalls.md diff --git a/snippets/articles/s/js-callbacks.md b/snippets/js/s/callbacks.md similarity index 100% rename from snippets/articles/s/js-callbacks.md rename to snippets/js/s/callbacks.md diff --git a/snippets/articles/s/js-cannot-extend-proxy-object.md b/snippets/js/s/cannot-extend-proxy-object.md similarity index 100% rename from snippets/articles/s/js-cannot-extend-proxy-object.md rename to snippets/js/s/cannot-extend-proxy-object.md diff --git a/snippets/js/s/chain-async.md b/snippets/js/s/chain-async-functions.md similarity index 100% rename from snippets/js/s/chain-async.md rename to snippets/js/s/chain-async-functions.md diff --git a/snippets/js/s/check-prop.md b/snippets/js/s/check-property.md similarity index 100% rename from snippets/js/s/check-prop.md rename to snippets/js/s/check-property.md diff --git a/snippets/js/s/chunkify.md b/snippets/js/s/chunk-iterable.md similarity index 100% rename from snippets/js/s/chunkify.md rename to snippets/js/s/chunk-iterable.md diff --git a/snippets/articles/s/javascript-classical-vs-prototypal-inheritance.md b/snippets/js/s/classical-vs-prototypal-inheritance.md similarity index 100% rename from snippets/articles/s/javascript-classical-vs-prototypal-inheritance.md rename to snippets/js/s/classical-vs-prototypal-inheritance.md diff --git a/snippets/js/s/closest.md b/snippets/js/s/closest-numeric-match.md similarity index 100% rename from snippets/js/s/closest.md rename to snippets/js/s/closest-numeric-match.md diff --git a/snippets/articles/s/javascript-closures.md b/snippets/js/s/closures.md similarity index 100% rename from snippets/articles/s/javascript-closures.md rename to snippets/js/s/closures.md diff --git a/snippets/articles/s/code-anatomy-chaining-reduce-for-loop.md b/snippets/js/s/code-anatomy-chaining-reduce-for-loop.md similarity index 100% rename from snippets/articles/s/code-anatomy-chaining-reduce-for-loop.md rename to snippets/js/s/code-anatomy-chaining-reduce-for-loop.md diff --git a/snippets/articles/s/code-anatomy-optimizing-recursion.md b/snippets/js/s/code-anatomy-optimizing-recursion.md similarity index 96% rename from snippets/articles/s/code-anatomy-optimizing-recursion.md rename to snippets/js/s/code-anatomy-optimizing-recursion.md index 2fc847056..18ebb4f10 100644 --- a/snippets/articles/s/code-anatomy-optimizing-recursion.md +++ b/snippets/js/s/code-anatomy-optimizing-recursion.md @@ -54,7 +54,7 @@ As you can see, for each value of `n`, `fibonacciNumber` will be called twice, o ### Calculation memoization -The solution to this problem, and the first trick that you can use to speed up recursive functions, is to use memoization. We already published [a great blog post on memoization](/articles/s/javascript-memoization/) a little while back, so be sure to check it out to learn more about the subject. Here's our `fibonacciNumber` function, using memoization: +The solution to this problem, and the first trick that you can use to speed up recursive functions, is to use memoization. We already published [a great blog post on memoization](/js/s/memoization/) a little while back, so be sure to check it out to learn more about the subject. Here's our `fibonacciNumber` function, using memoization: ```js const fibonacciCache = new Map(); diff --git a/snippets/js/s/is-empty.md b/snippets/js/s/collection-is-empty.md similarity index 100% rename from snippets/js/s/is-empty.md rename to snippets/js/s/collection-is-empty.md diff --git a/snippets/js/s/combine.md b/snippets/js/s/combine-object-arrays.md similarity index 100% rename from snippets/js/s/combine.md rename to snippets/js/s/combine-object-arrays.md diff --git a/snippets/js/s/get-cmd-args.md b/snippets/js/s/command-line-arguments.md similarity index 100% rename from snippets/js/s/get-cmd-args.md rename to snippets/js/s/command-line-arguments.md diff --git a/snippets/articles/s/common-regexp-cheatsheet.md b/snippets/js/s/common-regexp-cheatsheet.md similarity index 100% rename from snippets/articles/s/common-regexp-cheatsheet.md rename to snippets/js/s/common-regexp-cheatsheet.md diff --git a/snippets/js/s/compact.md b/snippets/js/s/compact-array.md similarity index 100% rename from snippets/js/s/compact.md rename to snippets/js/s/compact-array.md diff --git a/snippets/js/s/compact-join.md b/snippets/js/s/compact-join-array.md similarity index 100% rename from snippets/js/s/compact-join.md rename to snippets/js/s/compact-join-array.md diff --git a/snippets/articles/s/js-compare-string-case-accent-insensitive.md b/snippets/js/s/compare-string-case-accent-insensitive.md similarity index 100% rename from snippets/articles/s/js-compare-string-case-accent-insensitive.md rename to snippets/js/s/compare-string-case-accent-insensitive.md diff --git a/snippets/js/s/compose.md b/snippets/js/s/compose-functions.md similarity index 100% rename from snippets/js/s/compose.md rename to snippets/js/s/compose-functions.md diff --git a/snippets/js/s/when.md b/snippets/js/s/conditionally-apply-function.md similarity index 100% rename from snippets/js/s/when.md rename to snippets/js/s/conditionally-apply-function.md diff --git a/snippets/js/s/aperture.md b/snippets/js/s/consecutive-element-subarrays.md similarity index 100% rename from snippets/js/s/aperture.md rename to snippets/js/s/consecutive-element-subarrays.md diff --git a/snippets/articles/s/console-log-cheatsheet.md b/snippets/js/s/console-log-cheatsheet.md similarity index 100% rename from snippets/articles/s/console-log-cheatsheet.md rename to snippets/js/s/console-log-cheatsheet.md diff --git a/snippets/articles/s/js-construct-url.md b/snippets/js/s/construct-url.md similarity index 95% rename from snippets/articles/s/js-construct-url.md rename to snippets/js/s/construct-url.md index 1ff3793fe..066d69e05 100644 --- a/snippets/articles/s/js-construct-url.md +++ b/snippets/js/s/construct-url.md @@ -63,4 +63,4 @@ url.toString(); Admittedly, using the `URL` object can be a bit more verbose, but it's a worthwhile tradeoff. The code is much more readable and maintainable, and it's less prone to errors. Query parameters are now encoded properly, and delimiters are added automatically. -While query parameters are the most common issue when dealing with URLs, the `URL` object can be useful in many other situations. For example, you can change the protocol, hostname, port, path, hash, etc. of a URL, or even parse an existing URL into its components. If you're interested, you should check out previous articles about how you can [edit URL parameters](/articles/s/js-edit-url-params) and the [`window.location` cheat sheet](/articles/s/js-window-location-cheatsheet). +While query parameters are the most common issue when dealing with URLs, the `URL` object can be useful in many other situations. For example, you can change the protocol, hostname, port, path, hash, etc. of a URL, or even parse an existing URL into its components. If you're interested, you should check out previous articles about how you can [edit URL parameters](/js/s/edit-url-params) and the [`window.location` cheat sheet](/js/s/window-location-cheatsheet). diff --git a/snippets/js/s/converge.md b/snippets/js/s/converge-branching-functions.md similarity index 100% rename from snippets/js/s/converge.md rename to snippets/js/s/converge-branching-functions.md diff --git a/snippets/js/s/spread-over.md b/snippets/js/s/convert-function-from-variadic.md similarity index 100% rename from snippets/js/s/spread-over.md rename to snippets/js/s/convert-function-from-variadic.md diff --git a/snippets/js/s/collect-into.md b/snippets/js/s/convert-function-to-variadic.md similarity index 100% rename from snippets/js/s/collect-into.md rename to snippets/js/s/convert-function-to-variadic.md diff --git a/snippets/js/s/map-to-object.md b/snippets/js/s/convert-map-to-object.md similarity index 100% rename from snippets/js/s/map-to-object.md rename to snippets/js/s/convert-map-to-object.md diff --git a/snippets/js/s/object-to-map.md b/snippets/js/s/convert-object-to-map.md similarity index 100% rename from snippets/js/s/object-to-map.md rename to snippets/js/s/convert-object-to-map.md diff --git a/snippets/js/s/untildify.md b/snippets/js/s/convert-to-absolute-path.md similarity index 100% rename from snippets/js/s/untildify.md rename to snippets/js/s/convert-to-absolute-path.md diff --git a/snippets/articles/s/cookies-local-storage-session.md b/snippets/js/s/cookies-local-storage-session.md similarity index 100% rename from snippets/articles/s/cookies-local-storage-session.md rename to snippets/js/s/cookies-local-storage-session.md diff --git a/snippets/articles/s/javascript-copy-array.md b/snippets/js/s/copy-array.md similarity index 100% rename from snippets/articles/s/javascript-copy-array.md rename to snippets/js/s/copy-array.md diff --git a/snippets/js/s/copy-sign.md b/snippets/js/s/copy-sign-to-number.md similarity index 100% rename from snippets/js/s/copy-sign.md rename to snippets/js/s/copy-sign-to-number.md diff --git a/snippets/articles/s/copy-text-to-clipboard-with-javascript.md b/snippets/js/s/copy-text-to-clipboard.md similarity index 100% rename from snippets/articles/s/copy-text-to-clipboard-with-javascript.md rename to snippets/js/s/copy-text-to-clipboard.md diff --git a/snippets/articles/s/cors-explained.md b/snippets/js/s/cors-explained.md similarity index 93% rename from snippets/articles/s/cors-explained.md rename to snippets/js/s/cors-explained.md index b6df95bbe..7aa1eb630 100644 --- a/snippets/articles/s/cors-explained.md +++ b/snippets/js/s/cors-explained.md @@ -10,7 +10,7 @@ excerpt: CORS (Cross-Origin Resource Sharing) trips up many developers, but it's dateModified: 2023-05-07T05:00:00-04:00 --- -When it comes to HTTP, an **origin** is defined by several different aspects of a URL. As mentioned in a [previous article](/articles/s/js-window-location-cheatsheet/), the origin is composed of the following: +When it comes to HTTP, an **origin** is defined by several different aspects of a URL. As mentioned in a [previous article](/js/s/window-location-cheatsheet/), the origin is composed of the following: - The **protocol** (e.g. `http` or `https`) - The **hostname** (e.g. `30secondsofcode.org`) diff --git a/snippets/js/s/count-by.md b/snippets/js/s/count-grouped-elements.md similarity index 100% rename from snippets/js/s/count-by.md rename to snippets/js/s/count-grouped-elements.md diff --git a/snippets/js/s/create-dir-if-not-exists.md b/snippets/js/s/create-directory-if-not-exists.md similarity index 100% rename from snippets/js/s/create-dir-if-not-exists.md rename to snippets/js/s/create-directory-if-not-exists.md diff --git a/snippets/articles/s/js-create-element.md b/snippets/js/s/create-html-elements.md similarity index 100% rename from snippets/articles/s/js-create-element.md rename to snippets/js/s/create-html-elements.md diff --git a/snippets/js/s/x-prod.md b/snippets/js/s/cross-product-of-arrays.md similarity index 100% rename from snippets/js/s/x-prod.md rename to snippets/js/s/cross-product-of-arrays.md diff --git a/snippets/js/s/get-protocol.md b/snippets/js/s/current-page-protocol.md similarity index 100% rename from snippets/js/s/get-protocol.md rename to snippets/js/s/current-page-protocol.md diff --git a/snippets/js/s/curry.md b/snippets/js/s/curry-function.md similarity index 100% rename from snippets/js/s/curry.md rename to snippets/js/s/curry-function.md diff --git a/snippets/articles/s/js-data-structures-binary-search-tree.md b/snippets/js/s/data-structures-binary-search-tree.md similarity index 100% rename from snippets/articles/s/js-data-structures-binary-search-tree.md rename to snippets/js/s/data-structures-binary-search-tree.md diff --git a/snippets/articles/s/js-data-structures-binary-tree.md b/snippets/js/s/data-structures-binary-tree.md similarity index 100% rename from snippets/articles/s/js-data-structures-binary-tree.md rename to snippets/js/s/data-structures-binary-tree.md diff --git a/snippets/articles/s/js-data-structures-doubly-linked-list.md b/snippets/js/s/data-structures-doubly-linked-list.md similarity index 100% rename from snippets/articles/s/js-data-structures-doubly-linked-list.md rename to snippets/js/s/data-structures-doubly-linked-list.md diff --git a/snippets/articles/s/js-data-structures-graph.md b/snippets/js/s/data-structures-graph.md similarity index 100% rename from snippets/articles/s/js-data-structures-graph.md rename to snippets/js/s/data-structures-graph.md diff --git a/snippets/articles/s/js-data-structures-linked-list.md b/snippets/js/s/data-structures-linked-list.md similarity index 100% rename from snippets/articles/s/js-data-structures-linked-list.md rename to snippets/js/s/data-structures-linked-list.md diff --git a/snippets/articles/s/js-data-structures-queue.md b/snippets/js/s/data-structures-queue.md similarity index 100% rename from snippets/articles/s/js-data-structures-queue.md rename to snippets/js/s/data-structures-queue.md diff --git a/snippets/articles/s/js-data-structures-stack.md b/snippets/js/s/data-structures-stack.md similarity index 100% rename from snippets/articles/s/js-data-structures-stack.md rename to snippets/js/s/data-structures-stack.md diff --git a/snippets/articles/s/js-data-structures-tree.md b/snippets/js/s/data-structures-tree.md similarity index 100% rename from snippets/articles/s/js-data-structures-tree.md rename to snippets/js/s/data-structures-tree.md diff --git a/snippets/articles/s/javascript-date-comparison.md b/snippets/js/s/date-comparison.md similarity index 100% rename from snippets/articles/s/javascript-date-comparison.md rename to snippets/js/s/date-comparison.md diff --git a/snippets/js/s/get-days-diff-between-dates.md b/snippets/js/s/date-difference-in-days.md similarity index 100% rename from snippets/js/s/get-days-diff-between-dates.md rename to snippets/js/s/date-difference-in-days.md diff --git a/snippets/js/s/get-hours-diff-between-dates.md b/snippets/js/s/date-difference-in-hours.md similarity index 100% rename from snippets/js/s/get-hours-diff-between-dates.md rename to snippets/js/s/date-difference-in-hours.md diff --git a/snippets/js/s/get-minutes-diff-between-dates.md b/snippets/js/s/date-difference-in-minutes.md similarity index 100% rename from snippets/js/s/get-minutes-diff-between-dates.md rename to snippets/js/s/date-difference-in-minutes.md diff --git a/snippets/js/s/get-months-diff-between-dates.md b/snippets/js/s/date-difference-in-months.md similarity index 100% rename from snippets/js/s/get-months-diff-between-dates.md rename to snippets/js/s/date-difference-in-months.md diff --git a/snippets/js/s/get-seconds-diff-between-dates.md b/snippets/js/s/date-difference-in-seconds.md similarity index 100% rename from snippets/js/s/get-seconds-diff-between-dates.md rename to snippets/js/s/date-difference-in-seconds.md diff --git a/snippets/js/s/count-week-days-between.md b/snippets/js/s/date-difference-in-weekdays.md similarity index 100% rename from snippets/js/s/count-week-days-between.md rename to snippets/js/s/date-difference-in-weekdays.md diff --git a/snippets/js/s/from-timestamp.md b/snippets/js/s/date-from-unix-timestamp.md similarity index 100% rename from snippets/js/s/from-timestamp.md rename to snippets/js/s/date-from-unix-timestamp.md diff --git a/snippets/js/s/is-after-date.md b/snippets/js/s/date-is-after-another-date.md similarity index 100% rename from snippets/js/s/is-after-date.md rename to snippets/js/s/date-is-after-another-date.md diff --git a/snippets/js/s/is-before-date.md b/snippets/js/s/date-is-before-another-date.md similarity index 100% rename from snippets/js/s/is-before-date.md rename to snippets/js/s/date-is-before-another-date.md diff --git a/snippets/js/s/is-between-dates.md b/snippets/js/s/date-is-between-two-dates.md similarity index 100% rename from snippets/js/s/is-between-dates.md rename to snippets/js/s/date-is-between-two-dates.md diff --git a/snippets/js/s/is-same-date.md b/snippets/js/s/date-is-same-as-another-date.md similarity index 100% rename from snippets/js/s/is-same-date.md rename to snippets/js/s/date-is-same-as-another-date.md diff --git a/snippets/js/s/is-weekday.md b/snippets/js/s/date-is-weekday.md similarity index 100% rename from snippets/js/s/is-weekday.md rename to snippets/js/s/date-is-weekday.md diff --git a/snippets/js/s/is-weekend.md b/snippets/js/s/date-is-weekend.md similarity index 100% rename from snippets/js/s/is-weekend.md rename to snippets/js/s/date-is-weekend.md diff --git a/snippets/js/s/tomorrow.md b/snippets/js/s/date-tomorrow.md similarity index 100% rename from snippets/js/s/tomorrow.md rename to snippets/js/s/date-tomorrow.md diff --git a/snippets/js/s/yesterday.md b/snippets/js/s/date-yesterday.md similarity index 100% rename from snippets/js/s/yesterday.md rename to snippets/js/s/date-yesterday.md diff --git a/snippets/js/s/debounce.md b/snippets/js/s/debounce-function.md similarity index 100% rename from snippets/js/s/debounce.md rename to snippets/js/s/debounce-function.md diff --git a/snippets/articles/s/js-decimal-to-hex.md b/snippets/js/s/decimal-to-hex.md similarity index 100% rename from snippets/articles/s/js-decimal-to-hex.md rename to snippets/js/s/decimal-to-hex.md diff --git a/snippets/js/s/atob.md b/snippets/js/s/decode-base64-encoded-string.md similarity index 100% rename from snippets/js/s/atob.md rename to snippets/js/s/decode-base64-encoded-string.md diff --git a/snippets/js/s/deep-clone.md b/snippets/js/s/deep-clone-object.md similarity index 100% rename from snippets/js/s/deep-clone.md rename to snippets/js/s/deep-clone-object.md diff --git a/snippets/js/s/equals.md b/snippets/js/s/deep-equality-comparison.md similarity index 100% rename from snippets/js/s/equals.md rename to snippets/js/s/deep-equality-comparison.md diff --git a/snippets/js/s/deep-flatten.md b/snippets/js/s/deep-flatten-array.md similarity index 100% rename from snippets/js/s/deep-flatten.md rename to snippets/js/s/deep-flatten-array.md diff --git a/snippets/articles/s/javascript-deep-freeze-object.md b/snippets/js/s/deep-freeze-object.md similarity index 100% rename from snippets/articles/s/javascript-deep-freeze-object.md rename to snippets/js/s/deep-freeze-object.md diff --git a/snippets/js/s/deep-get.md b/snippets/js/s/deep-get-object-value.md similarity index 100% rename from snippets/js/s/deep-get.md rename to snippets/js/s/deep-get-object-value.md diff --git a/snippets/js/s/deep-map-keys.md b/snippets/js/s/deep-map-object-keys.md similarity index 100% rename from snippets/js/s/deep-map-keys.md rename to snippets/js/s/deep-map-object-keys.md diff --git a/snippets/js/s/deep-merge.md b/snippets/js/s/deep-merge-objects.md similarity index 100% rename from snippets/js/s/deep-merge.md rename to snippets/js/s/deep-merge-objects.md diff --git a/snippets/js/s/defaults.md b/snippets/js/s/default-values-for-object-properties.md similarity index 100% rename from snippets/js/s/defaults.md rename to snippets/js/s/default-values-for-object-properties.md diff --git a/snippets/js/s/defer.md b/snippets/js/s/defer-function.md similarity index 100% rename from snippets/js/s/defer.md rename to snippets/js/s/defer-function.md diff --git a/snippets/js/s/delay-async.md b/snippets/js/s/delay-async.md new file mode 100644 index 000000000..3a6b61d4a --- /dev/null +++ b/snippets/js/s/delay-async.md @@ -0,0 +1,24 @@ +--- +title: Delay async function execution +type: snippet +language: javascript +tags: [function,promise] +cover: sleepy-cat +dateModified: 2020-10-22T20:24:30+03:00 +--- + +Delays the execution of an asynchronous function. + +- Delay executing part of an `async` function, by putting it to sleep, returning a `Promise`. + +```js +const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); +``` + +```js +async function sleepyWork() { + console.log("I'm going to sleep for 1 second."); + await sleep(1000); + console.log('I woke up after 1 second.'); +} +``` diff --git a/snippets/js/s/delay.md b/snippets/js/s/delay-function.md similarity index 100% rename from snippets/js/s/delay.md rename to snippets/js/s/delay-function.md diff --git a/snippets/articles/s/javascript-destructuring-assignment.md b/snippets/js/s/destructuring-assignment.md similarity index 100% rename from snippets/articles/s/javascript-destructuring-assignment.md rename to snippets/js/s/destructuring-assignment.md diff --git a/snippets/articles/s/detect-caps-lock-is-on.md b/snippets/js/s/detect-caps-lock-is-on.md similarity index 100% rename from snippets/articles/s/detect-caps-lock-is-on.md rename to snippets/js/s/detect-caps-lock-is-on.md diff --git a/snippets/articles/s/js-detect-undefined-object-property.md b/snippets/js/s/detect-undefined-object-property.md similarity index 100% rename from snippets/articles/s/js-detect-undefined-object-property.md rename to snippets/js/s/detect-undefined-object-property.md diff --git a/snippets/js/s/digitize.md b/snippets/js/s/digitize-number.md similarity index 100% rename from snippets/js/s/digitize.md rename to snippets/js/s/digitize-number.md diff --git a/snippets/js/s/is-disjoint.md b/snippets/js/s/disjointed-iterables.md similarity index 100% rename from snippets/js/s/is-disjoint.md rename to snippets/js/s/disjointed-iterables.md diff --git a/snippets/js/s/distance.md b/snippets/js/s/distance-between-two-points.md similarity index 100% rename from snippets/js/s/distance.md rename to snippets/js/s/distance-between-two-points.md diff --git a/snippets/articles/s/js-double-negation-operator.md b/snippets/js/s/double-negation-operator.md similarity index 80% rename from snippets/articles/s/js-double-negation-operator.md rename to snippets/js/s/double-negation-operator.md index 56c5e0da5..350e99312 100644 --- a/snippets/articles/s/js-double-negation-operator.md +++ b/snippets/js/s/double-negation-operator.md @@ -20,7 +20,7 @@ const y = null; !!y; // false ``` -Using the double negation operator is functionally equivalent to using the `Boolean()` function, which we explored in depth in a [previous article](/articles/s/javascript-boolean-function). In terms of readability and usability, I would still suggest using the `Boolean()` function. It conveys the intent of the operation more clearly, and it's easier to understand at a glance. +Using the double negation operator is functionally equivalent to using the `Boolean()` function, which we explored in depth in a [previous article](/js/s/boolean-function). In terms of readability and usability, I would still suggest using the `Boolean()` function. It conveys the intent of the operation more clearly, and it's easier to understand at a glance. ```js const x = 1; diff --git a/snippets/js/s/drop-while.md b/snippets/js/s/drop-array-elements-from-left-while.md similarity index 91% rename from snippets/js/s/drop-while.md rename to snippets/js/s/drop-array-elements-from-left-while.md index a9b215bdf..41842c896 100644 --- a/snippets/js/s/drop-while.md +++ b/snippets/js/s/drop-array-elements-from-left-while.md @@ -1,5 +1,5 @@ --- -title: Drop list elements from the left based on function +title: Drop array elements from the left based on function type: snippet language: javascript tags: [array] diff --git a/snippets/js/s/drop.md b/snippets/js/s/drop-array-elements-from-left.md similarity index 92% rename from snippets/js/s/drop.md rename to snippets/js/s/drop-array-elements-from-left.md index 9022cdcc1..20de321b7 100644 --- a/snippets/js/s/drop.md +++ b/snippets/js/s/drop-array-elements-from-left.md @@ -1,5 +1,5 @@ --- -title: Drop list elements from the left +title: Drop array elements from the left type: snippet language: javascript tags: [array] diff --git a/snippets/js/s/drop-right-while.md b/snippets/js/s/drop-array-elements-from-right-while.md similarity index 91% rename from snippets/js/s/drop-right-while.md rename to snippets/js/s/drop-array-elements-from-right-while.md index c30ac9c99..5a7794ea1 100644 --- a/snippets/js/s/drop-right-while.md +++ b/snippets/js/s/drop-array-elements-from-right-while.md @@ -1,5 +1,5 @@ --- -title: Drop list elements from the right based on function +title: Drop array elements from the right based on function type: snippet language: javascript tags: [array] diff --git a/snippets/js/s/drop-right.md b/snippets/js/s/drop-array-elements-from-right.md similarity index 92% rename from snippets/js/s/drop-right.md rename to snippets/js/s/drop-array-elements-from-right.md index ec024d275..cab06df18 100644 --- a/snippets/js/s/drop-right.md +++ b/snippets/js/s/drop-array-elements-from-right.md @@ -1,5 +1,5 @@ --- -title: Drop list elements from the right +title: Drop array elements from the right type: snippet language: javascript tags: [array] diff --git a/snippets/articles/s/js-dynamic-getter-chain-proxy.md b/snippets/js/s/dynamic-getter-chain-proxy.md similarity index 95% rename from snippets/articles/s/js-dynamic-getter-chain-proxy.md rename to snippets/js/s/dynamic-getter-chain-proxy.md index a6c8d4eca..f4c202fce 100644 --- a/snippets/articles/s/js-dynamic-getter-chain-proxy.md +++ b/snippets/js/s/dynamic-getter-chain-proxy.md @@ -12,7 +12,7 @@ dateModified: 2023-05-28T05:00:00-04:00 The dawn of ES6 brought about jQuery's fall from grace, as a lot of the conveniences it afforded developers were now available in the language itself. However, jQuery's API design was convenient in many ways that native JavaScript often isn't. One of the most practical things jQuery offered was its ability to chain methods together, minimizing duplication and making code more readable. -Looking at the use case at hand, I thought that I could stitch together a general-purpose solution using JavaScript's `Proxy` object. In fact, I think that the concept of dynamic getters and setters that I described in [my previous post](/articles/s/js-dynamic-getter-setter-proxy) is a great place to start. +Looking at the use case at hand, I thought that I could stitch together a general-purpose solution using JavaScript's `Proxy` object. In fact, I think that the concept of dynamic getters and setters that I described in [my previous post](/js/s/dynamic-getter-setter-proxy) is a great place to start. To recap, intercepting the behavior of the `get` and `set` traps of a `Proxy` object allows us to create dynamic accessors for objects. This is particularly useful when the shape of the data is not known in advance, or when the value of a property needs to be manipulated before it is returned. diff --git a/snippets/articles/s/js-dynamic-getter-setter-proxy.md b/snippets/js/s/dynamic-getter-setter-proxy.md similarity index 100% rename from snippets/articles/s/js-dynamic-getter-setter-proxy.md rename to snippets/js/s/dynamic-getter-setter-proxy.md diff --git a/snippets/articles/s/js-dynamic-properties-are-slow.md b/snippets/js/s/dynamic-properties-are-slow.md similarity index 100% rename from snippets/articles/s/js-dynamic-properties-are-slow.md rename to snippets/js/s/dynamic-properties-are-slow.md diff --git a/snippets/articles/s/js-edit-url-params.md b/snippets/js/s/edit-url-params.md similarity index 100% rename from snippets/articles/s/js-edit-url-params.md rename to snippets/js/s/edit-url-params.md diff --git a/snippets/articles/s/js-element-from-point.md b/snippets/js/s/element-from-point.md similarity index 100% rename from snippets/articles/s/js-element-from-point.md rename to snippets/js/s/element-from-point.md diff --git a/snippets/articles/s/js-email-validation.md b/snippets/js/s/email-validation.md similarity index 100% rename from snippets/articles/s/js-email-validation.md rename to snippets/js/s/email-validation.md diff --git a/snippets/articles/s/javascript-empty-array.md b/snippets/js/s/empty-array.md similarity index 100% rename from snippets/articles/s/javascript-empty-array.md rename to snippets/js/s/empty-array.md diff --git a/snippets/js/s/btoa.md b/snippets/js/s/encode-string-to-base64.md similarity index 100% rename from snippets/js/s/btoa.md rename to snippets/js/s/encode-string-to-base64.md diff --git a/snippets/articles/s/javascript-encodeuri-encodeuricomponent.md b/snippets/js/s/encodeuri-encodeuricomponent.md similarity index 100% rename from snippets/articles/s/javascript-encodeuri-encodeuricomponent.md rename to snippets/js/s/encodeuri-encodeuricomponent.md diff --git a/snippets/articles/s/javascript-enum.md b/snippets/js/s/enum.md similarity index 100% rename from snippets/articles/s/javascript-enum.md rename to snippets/js/s/enum.md diff --git a/snippets/articles/s/javascript-equality.md b/snippets/js/s/equality.md similarity index 100% rename from snippets/articles/s/javascript-equality.md rename to snippets/js/s/equality.md diff --git a/snippets/articles/s/eslint-refactor-for-in.md b/snippets/js/s/eslint-refactor-for-in.md similarity index 100% rename from snippets/articles/s/eslint-refactor-for-in.md rename to snippets/js/s/eslint-refactor-for-in.md diff --git a/snippets/articles/s/javascript-event-bubbling-capturing-delegation.md b/snippets/js/s/event-bubbling-capturing-delegation.md similarity index 100% rename from snippets/articles/s/javascript-event-bubbling-capturing-delegation.md rename to snippets/js/s/event-bubbling-capturing-delegation.md diff --git a/snippets/articles/s/javascript-event-loop-explained.md b/snippets/js/s/event-loop-explained.md similarity index 100% rename from snippets/articles/s/javascript-event-loop-explained.md rename to snippets/js/s/event-loop-explained.md diff --git a/snippets/js/s/every-nth.md b/snippets/js/s/every-nth-element.md similarity index 100% rename from snippets/js/s/every-nth.md rename to snippets/js/s/every-nth-element.md diff --git a/snippets/articles/s/javascript-evil-closures.md b/snippets/js/s/evil-closures.md similarity index 95% rename from snippets/articles/s/javascript-evil-closures.md rename to snippets/js/s/evil-closures.md index 553c5a490..2fb32179d 100644 --- a/snippets/articles/s/javascript-evil-closures.md +++ b/snippets/js/s/evil-closures.md @@ -12,7 +12,7 @@ dateModified: 2022-05-18T05:00:00-04:00 JavaScript closures are used frequently, yet often misunderstood. Understanding them in depth is crucial to be able to write clean, maintainable and bug-free code. We previously discussed what they are and how they work. -I strongly recommend you read the [previous article on closures](/articles/s/javascript-closures) if you haven't already. Instead of rehashing the same information, I would like to discuss the dangers of using closures and present my view on the topic. +I strongly recommend you read the [previous article on closures](/js/s/closures) if you haven't already. Instead of rehashing the same information, I would like to discuss the dangers of using closures and present my view on the topic. ### Hidden state diff --git a/snippets/articles/s/javascript-listen-once.md b/snippets/js/s/execute-event-handler-once.md similarity index 100% rename from snippets/articles/s/javascript-listen-once.md rename to snippets/js/s/execute-event-handler-once.md diff --git a/snippets/articles/s/javascript-expression-statement.md b/snippets/js/s/expression-statement.md similarity index 100% rename from snippets/articles/s/javascript-expression-statement.md rename to snippets/js/s/expression-statement.md diff --git a/snippets/articles/s/js-fast-remove-array-element.md b/snippets/js/s/fast-remove-array-element.md similarity index 100% rename from snippets/articles/s/js-fast-remove-array-element.md rename to snippets/js/s/fast-remove-array-element.md diff --git a/snippets/js/s/reduced-filter.md b/snippets/js/s/filter-matching-and-unspecified-values.md similarity index 100% rename from snippets/js/s/reduced-filter.md rename to snippets/js/s/filter-matching-and-unspecified-values.md diff --git a/snippets/js/s/filter-non-unique.md b/snippets/js/s/filter-non-unique-array-values.md similarity index 100% rename from snippets/js/s/filter-non-unique.md rename to snippets/js/s/filter-non-unique-array-values.md diff --git a/snippets/js/s/without.md b/snippets/js/s/filter-out-matching-array-elements.md similarity index 100% rename from snippets/js/s/without.md rename to snippets/js/s/filter-out-matching-array-elements.md diff --git a/snippets/js/s/filter-unique.md b/snippets/js/s/filter-unique-array-values.md similarity index 100% rename from snippets/js/s/filter-unique.md rename to snippets/js/s/filter-unique-array-values.md diff --git a/snippets/js/s/find-key.md b/snippets/js/s/find-first-matching-key.md similarity index 100% rename from snippets/js/s/find-key.md rename to snippets/js/s/find-first-matching-key.md diff --git a/snippets/js/s/find-first-n.md b/snippets/js/s/find-first-n-matches.md similarity index 100% rename from snippets/js/s/find-first-n.md rename to snippets/js/s/find-first-n-matches.md diff --git a/snippets/js/s/find-last-index.md b/snippets/js/s/find-last-matching-index.md similarity index 100% rename from snippets/js/s/find-last-index.md rename to snippets/js/s/find-last-matching-index.md diff --git a/snippets/js/s/find-last-key.md b/snippets/js/s/find-last-matching-key.md similarity index 100% rename from snippets/js/s/find-last-key.md rename to snippets/js/s/find-last-matching-key.md diff --git a/snippets/js/s/find-last.md b/snippets/js/s/find-last-matching-value.md similarity index 100% rename from snippets/js/s/find-last.md rename to snippets/js/s/find-last-matching-value.md diff --git a/snippets/js/s/find-last-n.md b/snippets/js/s/find-last-n-matches.md similarity index 100% rename from snippets/js/s/find-last-n.md rename to snippets/js/s/find-last-n-matches.md diff --git a/snippets/js/s/find-keys.md b/snippets/js/s/find-matching-keys.md similarity index 100% rename from snippets/js/s/find-keys.md rename to snippets/js/s/find-matching-keys.md diff --git a/snippets/js/s/first-n.md b/snippets/js/s/first-n-elements.md similarity index 100% rename from snippets/js/s/first-n.md rename to snippets/js/s/first-n-elements.md diff --git a/snippets/js/s/flatten.md b/snippets/js/s/flatten-array.md similarity index 100% rename from snippets/js/s/flatten.md rename to snippets/js/s/flatten-array.md diff --git a/snippets/js/s/flip.md b/snippets/js/s/flip-function-arguments.md similarity index 100% rename from snippets/js/s/flip.md rename to snippets/js/s/flip-function-arguments.md diff --git a/snippets/articles/s/javascript-for-in-for-of-foreach.md b/snippets/js/s/for-in-for-of-foreach.md similarity index 100% rename from snippets/articles/s/javascript-for-in-for-of-foreach.md rename to snippets/js/s/for-in-for-of-foreach.md diff --git a/snippets/articles/s/javascript-for-loop-early-break.md b/snippets/js/s/for-loop-early-break.md similarity index 100% rename from snippets/articles/s/javascript-for-loop-early-break.md rename to snippets/js/s/for-loop-early-break.md diff --git a/snippets/js/s/frozen-set.md b/snippets/js/s/freeze-set-object.md similarity index 100% rename from snippets/js/s/frozen-set.md rename to snippets/js/s/freeze-set-object.md diff --git a/snippets/articles/s/js-frequency-map-data-structure.md b/snippets/js/s/frequency-map-data-structure.md similarity index 100% rename from snippets/articles/s/js-frequency-map-data-structure.md rename to snippets/js/s/frequency-map-data-structure.md diff --git a/snippets/js/s/ary.md b/snippets/js/s/function-arity.md similarity index 100% rename from snippets/js/s/ary.md rename to snippets/js/s/function-arity.md diff --git a/snippets/js/s/difference-with.md b/snippets/js/s/function-based-array-difference.md similarity index 100% rename from snippets/js/s/difference-with.md rename to snippets/js/s/function-based-array-difference.md diff --git a/snippets/js/s/all-equal-by.md b/snippets/js/s/function-based-array-element-equality.md similarity index 100% rename from snippets/js/s/all-equal-by.md rename to snippets/js/s/function-based-array-element-equality.md diff --git a/snippets/js/s/group-by.md b/snippets/js/s/function-based-array-element-grouping.md similarity index 100% rename from snippets/js/s/group-by.md rename to snippets/js/s/function-based-array-element-grouping.md diff --git a/snippets/js/s/all-unique-by.md b/snippets/js/s/function-based-array-element-uniqueness.md similarity index 100% rename from snippets/js/s/all-unique-by.md rename to snippets/js/s/function-based-array-element-uniqueness.md diff --git a/snippets/js/s/index-by.md b/snippets/js/s/function-based-array-indexing.md similarity index 100% rename from snippets/js/s/index-by.md rename to snippets/js/s/function-based-array-indexing.md diff --git a/snippets/js/s/intersection-with.md b/snippets/js/s/function-based-array-intersection.md similarity index 100% rename from snippets/js/s/intersection-with.md rename to snippets/js/s/function-based-array-intersection.md diff --git a/snippets/js/s/max-by.md b/snippets/js/s/function-based-array-max.md similarity index 100% rename from snippets/js/s/max-by.md rename to snippets/js/s/function-based-array-max.md diff --git a/snippets/js/s/reduce-which.md b/snippets/js/s/function-based-array-min-max.md similarity index 100% rename from snippets/js/s/reduce-which.md rename to snippets/js/s/function-based-array-min-max.md diff --git a/snippets/js/s/min-by.md b/snippets/js/s/function-based-array-min.md similarity index 100% rename from snippets/js/s/min-by.md rename to snippets/js/s/function-based-array-min.md diff --git a/snippets/js/s/filter-non-unique-by.md b/snippets/js/s/function-based-array-non-uniqueness-filter.md similarity index 100% rename from snippets/js/s/filter-non-unique-by.md rename to snippets/js/s/function-based-array-non-uniqueness-filter.md diff --git a/snippets/js/s/symmetric-difference-with.md b/snippets/js/s/function-based-array-symmetric-difference.md similarity index 92% rename from snippets/js/s/symmetric-difference-with.md rename to snippets/js/s/function-based-array-symmetric-difference.md index 11f2f71c6..e4df9ec58 100644 --- a/snippets/js/s/symmetric-difference-with.md +++ b/snippets/js/s/function-based-array-symmetric-difference.md @@ -1,5 +1,5 @@ --- -title: Array symmetric difference +title: Array symmetric difference based on function type: snippet language: javascript tags: [array] diff --git a/snippets/js/s/union-with.md b/snippets/js/s/function-based-array-union.md similarity index 100% rename from snippets/js/s/union-with.md rename to snippets/js/s/function-based-array-union.md diff --git a/snippets/js/s/unique-elements-by.md b/snippets/js/s/function-based-array-unique-values.md similarity index 100% rename from snippets/js/s/unique-elements-by.md rename to snippets/js/s/function-based-array-unique-values.md diff --git a/snippets/js/s/filter-unique-by.md b/snippets/js/s/function-based-array-uniqueness-filter.md similarity index 100% rename from snippets/js/s/filter-unique-by.md rename to snippets/js/s/function-based-array-uniqueness-filter.md diff --git a/snippets/js/s/matches-with.md b/snippets/js/s/function-based-object-property-matches.md similarity index 100% rename from snippets/js/s/matches-with.md rename to snippets/js/s/function-based-object-property-matches.md diff --git a/snippets/js/s/unique-elements-by-right.md b/snippets/js/s/function-based-reversed-array-unique-values.md similarity index 100% rename from snippets/js/s/unique-elements-by-right.md rename to snippets/js/s/function-based-reversed-array-unique-values.md diff --git a/snippets/js/s/sorted-index-by.md b/snippets/js/s/function-based-sorted-array-insertion-index.md similarity index 100% rename from snippets/js/s/sorted-index-by.md rename to snippets/js/s/function-based-sorted-array-insertion-index.md diff --git a/snippets/js/s/sorted-last-index-by.md b/snippets/js/s/function-based-sorted-array-last-insertion-index.md similarity index 100% rename from snippets/js/s/sorted-last-index-by.md rename to snippets/js/s/function-based-sorted-array-last-insertion-index.md diff --git a/snippets/articles/s/javascript-function-call-apply-bind.md b/snippets/js/s/function-call-apply-bind.md similarity index 100% rename from snippets/articles/s/javascript-function-call-apply-bind.md rename to snippets/js/s/function-call-apply-bind.md diff --git a/snippets/js/s/either.md b/snippets/js/s/function-logical-or.md similarity index 100% rename from snippets/js/s/either.md rename to snippets/js/s/function-logical-or.md diff --git a/snippets/js/s/functions.md b/snippets/js/s/function-names.md similarity index 100% rename from snippets/js/s/functions.md rename to snippets/js/s/function-names.md diff --git a/snippets/articles/s/javascript-range-generator.md b/snippets/js/s/generator-for-range.md similarity index 100% rename from snippets/articles/s/javascript-range-generator.md rename to snippets/js/s/generator-for-range.md diff --git a/snippets/js/s/get.md b/snippets/js/s/get-nested-object-value.md similarity index 100% rename from snippets/js/s/get.md rename to snippets/js/s/get-nested-object-value.md diff --git a/snippets/js/s/dig.md b/snippets/js/s/get-nested-value-in-object.md similarity index 100% rename from snippets/js/s/dig.md rename to snippets/js/s/get-nested-value-in-object.md diff --git a/snippets/js/s/zip-with.md b/snippets/js/s/group-array-elements-based-on-function.md similarity index 100% rename from snippets/js/s/zip-with.md rename to snippets/js/s/group-array-elements-based-on-function.md diff --git a/snippets/js/s/zip.md b/snippets/js/s/group-array-elements.md similarity index 100% rename from snippets/js/s/zip.md rename to snippets/js/s/group-array-elements.md diff --git a/snippets/js/s/zip-object.md b/snippets/js/s/group-array-into-object.md similarity index 100% rename from snippets/js/s/zip-object.md rename to snippets/js/s/group-array-into-object.md diff --git a/snippets/js/s/sdbm.md b/snippets/js/s/hash-string-into-number.md similarity index 100% rename from snippets/js/s/sdbm.md rename to snippets/js/s/hash-string-into-number.md diff --git a/snippets/js/s/hide.md b/snippets/js/s/hide-html-elements.md similarity index 100% rename from snippets/js/s/hide.md rename to snippets/js/s/hide-html-elements.md diff --git a/snippets/articles/s/javascript-higher-order-functions.md b/snippets/js/s/higher-order-functions.md similarity index 100% rename from snippets/articles/s/javascript-higher-order-functions.md rename to snippets/js/s/higher-order-functions.md diff --git a/snippets/js/s/has-class.md b/snippets/js/s/html-element-has-class.md similarity index 100% rename from snippets/js/s/has-class.md rename to snippets/js/s/html-element-has-class.md diff --git a/snippets/articles/s/javascript-iife.md b/snippets/js/s/iife.md similarity index 100% rename from snippets/articles/s/javascript-iife.md rename to snippets/js/s/iife.md diff --git a/snippets/articles/s/js-immutable-object-proxy.md b/snippets/js/s/immutable-object-proxy.md similarity index 97% rename from snippets/articles/s/js-immutable-object-proxy.md rename to snippets/js/s/immutable-object-proxy.md index 5d1fc22d5..0b8cc63eb 100644 --- a/snippets/articles/s/js-immutable-object-proxy.md +++ b/snippets/js/s/immutable-object-proxy.md @@ -10,7 +10,7 @@ excerpt: Freezing objects is not the only way to prevent mutations. Learn how yo dateModified: 2022-04-10T05:00:00-04:00 --- -Object mutability and its relation to the `const` keyword is a very common headache for developers. More often than not, when looking for ways to make an object immutable, `Object.freeze()` will pop up as a solution. We’ve explored this approach previously, elaborating on deep freezing solutions. You can read more about it in [this article](/articles/s/javascript-deep-freeze-object). +Object mutability and its relation to the `const` keyword is a very common headache for developers. More often than not, when looking for ways to make an object immutable, `Object.freeze()` will pop up as a solution. We’ve explored this approach previously, elaborating on deep freezing solutions. You can read more about it in [this article](/js/s/deep-freeze-object). While `Object.freeze()` is the more straightforward approach, it might not always be the best solution. This may be especially true when dealing with extensive object nesting or when objects have a very short life. For such cases, a different approach using the [Proxy object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy) might make more sense. Here’s what that looks like: diff --git a/snippets/articles/s/javascript-index-for-of-loop.md b/snippets/js/s/index-for-of-loop.md similarity index 94% rename from snippets/articles/s/javascript-index-for-of-loop.md rename to snippets/js/s/index-for-of-loop.md index 5084d3966..97a316993 100644 --- a/snippets/articles/s/javascript-index-for-of-loop.md +++ b/snippets/js/s/index-for-of-loop.md @@ -23,4 +23,4 @@ for (let [index, item] of items.entries()) { Moreover, you can use the spread operator (`...`) to convert a string into an array and then use `Array.prototype.entries()` the same way. Finally, both `Map` and `Set` prototypes provide a similar method (`Map.prototype.entries()` and `Set.prototype.entries()` respectively), which can be used the exact same way. -_If you're not familiar with `for...of` and its syntax, I highly recommending you take a look at [this article about the various iteration methods in JavaScript](/articles/s/javascript-for-in-for-of-foreach)._ +_If you're not familiar with `for...of` and its syntax, I highly recommending you take a look at [this article about the various iteration methods in JavaScript](/js/s/for-in-for-of-foreach)._ diff --git a/snippets/js/s/index-of-all.md b/snippets/js/s/index-of-all-matches.md similarity index 100% rename from snippets/js/s/index-of-all.md rename to snippets/js/s/index-of-all-matches.md diff --git a/snippets/js/s/initialize2-d-array.md b/snippets/js/s/initialize-2d-array.md similarity index 100% rename from snippets/js/s/initialize2-d-array.md rename to snippets/js/s/initialize-2d-array.md diff --git a/snippets/js/s/initialize-array-with-range-right.md b/snippets/js/s/initialize-array-with-reversed-range.md similarity index 100% rename from snippets/js/s/initialize-array-with-range-right.md rename to snippets/js/s/initialize-array-with-reversed-range.md diff --git a/snippets/js/s/initialize-nd-array.md b/snippets/js/s/initialize-n-dimensional-array.md similarity index 100% rename from snippets/js/s/initialize-nd-array.md rename to snippets/js/s/initialize-n-dimensional-array.md diff --git a/snippets/js/s/insert-after.md b/snippets/js/s/insert-html-string-after-element.md similarity index 100% rename from snippets/js/s/insert-after.md rename to snippets/js/s/insert-html-string-after-element.md diff --git a/snippets/js/s/insert-before.md b/snippets/js/s/insert-html-string-before-element.md similarity index 100% rename from snippets/js/s/insert-before.md rename to snippets/js/s/insert-html-string-before-element.md diff --git a/snippets/js/s/insert-at.md b/snippets/js/s/insert-value-at-array-index.md similarity index 100% rename from snippets/js/s/insert-at.md rename to snippets/js/s/insert-value-at-array-index.md diff --git a/snippets/js/s/sorted-index.md b/snippets/js/s/insertion-index-in-sorted-array.md similarity index 100% rename from snippets/js/s/sorted-index.md rename to snippets/js/s/insertion-index-in-sorted-array.md diff --git a/snippets/js/s/over.md b/snippets/js/s/invoke-functions-on-arguments.md similarity index 100% rename from snippets/js/s/over.md rename to snippets/js/s/invoke-functions-on-arguments.md diff --git a/snippets/js/s/is-iso-string.md b/snippets/js/s/is-iso-formatted-date.md similarity index 100% rename from snippets/js/s/is-iso-string.md rename to snippets/js/s/is-iso-formatted-date.md diff --git a/snippets/js/s/to-iso-string-with-timezone.md b/snippets/js/s/iso-format-date-with-timezone.md similarity index 100% rename from snippets/js/s/to-iso-string-with-timezone.md rename to snippets/js/s/iso-format-date-with-timezone.md diff --git a/snippets/articles/s/javascript-iterable-to-array.md b/snippets/js/s/iterable-to-array.md similarity index 100% rename from snippets/articles/s/javascript-iterable-to-array.md rename to snippets/js/s/iterable-to-array.md diff --git a/snippets/js/s/to-hash.md b/snippets/js/s/iterable-to-hash.md similarity index 100% rename from snippets/js/s/to-hash.md rename to snippets/js/s/iterable-to-hash.md diff --git a/snippets/js/s/times.md b/snippets/js/s/iterate-n-times.md similarity index 100% rename from snippets/js/s/times.md rename to snippets/js/s/iterate-n-times.md diff --git a/snippets/js/s/for-own.md b/snippets/js/s/iterate-object-properties.md similarity index 100% rename from snippets/js/s/for-own.md rename to snippets/js/s/iterate-object-properties.md diff --git a/snippets/articles/s/javascript-iterators.md b/snippets/js/s/iterators.md similarity index 87% rename from snippets/articles/s/javascript-iterators.md rename to snippets/js/s/iterators.md index b8d5cd7a9..d7ea905c5 100644 --- a/snippets/articles/s/javascript-iterators.md +++ b/snippets/js/s/iterators.md @@ -54,7 +54,7 @@ for (let item of myList) { } ``` -In the above example, we implement a [`LinkedList` data structure](/articles/s/js-data-structures-linked-list), that internally uses a `data` array. Each item in it has a `value` and some implementation-specific properties used to determine its position in the sequence. Objects constructed from this class are not iterable by default. To define an iterator we use `Symbol.iterator` and set it up so that the returned sequence is in order based on the internal implementation of the class, while the returned items only return their `value`. +In the above example, we implement a [`LinkedList` data structure](/js/s/data-structures-linked-list), that internally uses a `data` array. Each item in it has a `value` and some implementation-specific properties used to determine its position in the sequence. Objects constructed from this class are not iterable by default. To define an iterator we use `Symbol.iterator` and set it up so that the returned sequence is in order based on the internal implementation of the class, while the returned items only return their `value`. On a related note, iterators are just functions, meaning they can be called like any other function (e.g. to delegate the iteration to an existing iterator), while also not being restricted to the `Symbol.iterator` name. This allows us to define multiple iterators for the same object. Here's an example of these concepts at play: diff --git a/snippets/articles/s/jest-mock-global-methods.md b/snippets/js/s/jest-mock-global-methods.md similarity index 100% rename from snippets/articles/s/jest-mock-global-methods.md rename to snippets/js/s/jest-mock-global-methods.md diff --git a/snippets/js/s/join.md b/snippets/js/s/join-array-into-string.md similarity index 100% rename from snippets/js/s/join.md rename to snippets/js/s/join-array-into-string.md diff --git a/snippets/js/s/url-join.md b/snippets/js/s/join-url-segments.md similarity index 100% rename from snippets/js/s/url-join.md rename to snippets/js/s/join-url-segments.md diff --git a/snippets/articles/s/javascript-json-stringify-pick-keys.md b/snippets/js/s/json-stringify-pick-keys.md similarity index 100% rename from snippets/articles/s/javascript-json-stringify-pick-keys.md rename to snippets/js/s/json-stringify-pick-keys.md diff --git a/snippets/js/s/jso-nto-csv.md b/snippets/js/s/json-to-csv.md similarity index 100% rename from snippets/js/s/jso-nto-csv.md rename to snippets/js/s/json-to-csv.md diff --git a/snippets/js/s/juxt.md b/snippets/js/s/juxtapose-functions.md similarity index 100% rename from snippets/js/s/juxt.md rename to snippets/js/s/juxtapose-functions.md diff --git a/snippets/js/s/last.md b/snippets/js/s/last-array-element.md similarity index 100% rename from snippets/js/s/last.md rename to snippets/js/s/last-array-element.md diff --git a/snippets/articles/s/js-last-element-of-array.md b/snippets/js/s/last-element-of-array.md similarity index 100% rename from snippets/articles/s/js-last-element-of-array.md rename to snippets/js/s/last-element-of-array.md diff --git a/snippets/js/s/sorted-last-index.md b/snippets/js/s/last-insertion-index-in-sorted-array.md similarity index 100% rename from snippets/js/s/sorted-last-index.md rename to snippets/js/s/last-insertion-index-in-sorted-array.md diff --git a/snippets/js/s/last-n.md b/snippets/js/s/last-n-elements.md similarity index 100% rename from snippets/js/s/last-n.md rename to snippets/js/s/last-n-elements.md diff --git a/snippets/js/s/left-substr-generator.md b/snippets/js/s/left-substring-generator.md similarity index 100% rename from snippets/js/s/left-substr-generator.md rename to snippets/js/s/left-substring-generator.md diff --git a/snippets/articles/s/js-locale-sensitive-string-truncation.md b/snippets/js/s/locale-sensitive-string-truncation.md similarity index 100% rename from snippets/articles/s/js-locale-sensitive-string-truncation.md rename to snippets/js/s/locale-sensitive-string-truncation.md diff --git a/snippets/js/s/log-base.md b/snippets/js/s/logarithm-in-base.md similarity index 100% rename from snippets/js/s/log-base.md rename to snippets/js/s/logarithm-in-base.md diff --git a/snippets/js/s/complement.md b/snippets/js/s/logical-complement.md similarity index 100% rename from snippets/js/s/complement.md rename to snippets/js/s/logical-complement.md diff --git a/snippets/js/s/longest-item.md b/snippets/js/s/longest-array-element.md similarity index 100% rename from snippets/js/s/longest-item.md rename to snippets/js/s/longest-array-element.md diff --git a/snippets/articles/s/javascript-make-iterable.md b/snippets/js/s/make-iterable.md similarity index 100% rename from snippets/articles/s/javascript-make-iterable.md rename to snippets/js/s/make-iterable.md diff --git a/snippets/js/s/map-object.md b/snippets/js/s/map-array-to-object.md similarity index 100% rename from snippets/js/s/map-object.md rename to snippets/js/s/map-array-to-object.md diff --git a/snippets/js/s/map-consecutive.md b/snippets/js/s/map-consecutive-elements.md similarity index 100% rename from snippets/js/s/map-consecutive.md rename to snippets/js/s/map-consecutive-elements.md diff --git a/snippets/js/s/map-num-range.md b/snippets/js/s/map-number-to-range.md similarity index 100% rename from snippets/js/s/map-num-range.md rename to snippets/js/s/map-number-to-range.md diff --git a/snippets/js/s/map-keys.md b/snippets/js/s/map-object-keys.md similarity index 100% rename from snippets/js/s/map-keys.md rename to snippets/js/s/map-object-keys.md diff --git a/snippets/articles/s/js-map-vs-object.md b/snippets/js/s/map-vs-object.md similarity index 100% rename from snippets/articles/s/js-map-vs-object.md rename to snippets/js/s/map-vs-object.md diff --git a/snippets/js/s/average-by.md b/snippets/js/s/mapped-array-average.md similarity index 100% rename from snippets/js/s/average-by.md rename to snippets/js/s/mapped-array-average.md diff --git a/snippets/js/s/difference-by.md b/snippets/js/s/mapped-array-difference.md similarity index 100% rename from snippets/js/s/difference-by.md rename to snippets/js/s/mapped-array-difference.md diff --git a/snippets/js/s/intersection-by.md b/snippets/js/s/mapped-array-intersection.md similarity index 100% rename from snippets/js/s/intersection-by.md rename to snippets/js/s/mapped-array-intersection.md diff --git a/snippets/js/s/sum-by.md b/snippets/js/s/mapped-array-sum.md similarity index 100% rename from snippets/js/s/sum-by.md rename to snippets/js/s/mapped-array-sum.md diff --git a/snippets/js/s/symmetric-difference-by.md b/snippets/js/s/mapped-array-symmetric-difference.md similarity index 100% rename from snippets/js/s/symmetric-difference-by.md rename to snippets/js/s/mapped-array-symmetric-difference.md diff --git a/snippets/js/s/union-by.md b/snippets/js/s/mapped-array-union.md similarity index 100% rename from snippets/js/s/union-by.md rename to snippets/js/s/mapped-array-union.md diff --git a/snippets/js/s/matches.md b/snippets/js/s/match-object-properties.md similarity index 100% rename from snippets/js/s/matches.md rename to snippets/js/s/match-object-properties.md diff --git a/snippets/articles/s/javascript-memoization.md b/snippets/js/s/memoization.md similarity index 100% rename from snippets/articles/s/javascript-memoization.md rename to snippets/js/s/memoization.md diff --git a/snippets/js/s/memoize.md b/snippets/js/s/memoize-function.md similarity index 100% rename from snippets/js/s/memoize.md rename to snippets/js/s/memoize-function.md diff --git a/snippets/articles/s/javascript-merge-arrays.md b/snippets/js/s/merge-arrays.md similarity index 100% rename from snippets/articles/s/javascript-merge-arrays.md rename to snippets/js/s/merge-arrays.md diff --git a/snippets/js/s/merge.md b/snippets/js/s/merge-objects.md similarity index 100% rename from snippets/js/s/merge.md rename to snippets/js/s/merge-objects.md diff --git a/snippets/articles/s/javascript-modify-url-without-reload.md b/snippets/js/s/modify-url-without-reload.md similarity index 100% rename from snippets/articles/s/javascript-modify-url-without-reload.md rename to snippets/js/s/modify-url-without-reload.md diff --git a/snippets/articles/s/javascript-module-cheatsheet.md b/snippets/js/s/module-cheatsheet.md similarity index 100% rename from snippets/articles/s/javascript-module-cheatsheet.md rename to snippets/js/s/module-cheatsheet.md diff --git a/snippets/js/s/most-frequent.md b/snippets/js/s/most-frequent-array-element.md similarity index 100% rename from snippets/js/s/most-frequent.md rename to snippets/js/s/most-frequent-array-element.md diff --git a/snippets/js/s/most-performant.md b/snippets/js/s/most-performant-function.md similarity index 100% rename from snippets/js/s/most-performant.md rename to snippets/js/s/most-performant-function.md diff --git a/snippets/js/s/sample-size.md b/snippets/js/s/multiple-array-samples.md similarity index 100% rename from snippets/js/s/sample-size.md rename to snippets/js/s/multiple-array-samples.md diff --git a/snippets/js/s/max-n.md b/snippets/js/s/n-max-elements.md similarity index 100% rename from snippets/js/s/max-n.md rename to snippets/js/s/n-max-elements.md diff --git a/snippets/js/s/min-n.md b/snippets/js/s/n-min-elements.md similarity index 100% rename from snippets/js/s/min-n.md rename to snippets/js/s/n-min-elements.md diff --git a/snippets/articles/s/javascript-naming-conventions.md b/snippets/js/s/naming-conventions.md similarity index 100% rename from snippets/articles/s/javascript-naming-conventions.md rename to snippets/js/s/naming-conventions.md diff --git a/snippets/articles/s/js-native-data-structures.md b/snippets/js/s/native-data-structures.md similarity index 100% rename from snippets/articles/s/js-native-data-structures.md rename to snippets/js/s/native-data-structures.md diff --git a/snippets/js/s/negate.md b/snippets/js/s/negate-predicate.md similarity index 100% rename from snippets/js/s/negate.md rename to snippets/js/s/negate-predicate.md diff --git a/snippets/js/s/nest.md b/snippets/js/s/nest-objects.md similarity index 100% rename from snippets/js/s/nest.md rename to snippets/js/s/nest-objects.md diff --git a/snippets/articles/s/nodejs-chrome-debugging.md b/snippets/js/s/nodejs-chrome-debugging.md similarity index 100% rename from snippets/articles/s/nodejs-chrome-debugging.md rename to snippets/js/s/nodejs-chrome-debugging.md diff --git a/snippets/articles/s/nodejs-static-file-server.md b/snippets/js/s/nodejs-static-file-server.md similarity index 100% rename from snippets/articles/s/nodejs-static-file-server.md rename to snippets/js/s/nodejs-static-file-server.md diff --git a/snippets/articles/s/nodejs-test-module-introduction.md b/snippets/js/s/nodejs-test-module-introduction.md similarity index 100% rename from snippets/articles/s/nodejs-test-module-introduction.md rename to snippets/js/s/nodejs-test-module-introduction.md diff --git a/snippets/js/s/nth-arg.md b/snippets/js/s/nth-argument.md similarity index 100% rename from snippets/js/s/nth-arg.md rename to snippets/js/s/nth-argument.md diff --git a/snippets/js/s/nth-root.md b/snippets/js/s/nth-number-root.md similarity index 100% rename from snippets/js/s/nth-root.md rename to snippets/js/s/nth-number-root.md diff --git a/snippets/articles/s/javascript-nullish-coalescing-optional-chaining.md b/snippets/js/s/nullish-coalescing-optional-chaining.md similarity index 100% rename from snippets/articles/s/javascript-nullish-coalescing-optional-chaining.md rename to snippets/js/s/nullish-coalescing-optional-chaining.md diff --git a/snippets/js/s/in-range.md b/snippets/js/s/number-in-range.md similarity index 100% rename from snippets/js/s/in-range.md rename to snippets/js/s/number-in-range.md diff --git a/snippets/js/s/to-currency.md b/snippets/js/s/number-to-currency.md similarity index 100% rename from snippets/js/s/to-currency.md rename to snippets/js/s/number-to-currency.md diff --git a/snippets/js/s/to-decimal-mark.md b/snippets/js/s/number-to-decimal-mark.md similarity index 100% rename from snippets/js/s/to-decimal-mark.md rename to snippets/js/s/number-to-decimal-mark.md diff --git a/snippets/js/s/to-optional-fixed.md b/snippets/js/s/number-to-optional-fixed.md similarity index 100% rename from snippets/js/s/to-optional-fixed.md rename to snippets/js/s/number-to-optional-fixed.md diff --git a/snippets/articles/s/javascript-numeric-separator.md b/snippets/js/s/numeric-separator.md similarity index 100% rename from snippets/articles/s/javascript-numeric-separator.md rename to snippets/js/s/numeric-separator.md diff --git a/snippets/articles/s/javascript-object-array-proxy.md b/snippets/js/s/object-array-proxy.md similarity index 100% rename from snippets/articles/s/javascript-object-array-proxy.md rename to snippets/js/s/object-array-proxy.md diff --git a/snippets/articles/s/javascript-object-comparison.md b/snippets/js/s/object-comparison.md similarity index 100% rename from snippets/articles/s/javascript-object-comparison.md rename to snippets/js/s/object-comparison.md diff --git a/snippets/articles/s/js-object-freeze-vs-seal.md b/snippets/js/s/object-freeze-vs-seal.md similarity index 97% rename from snippets/articles/s/js-object-freeze-vs-seal.md rename to snippets/js/s/object-freeze-vs-seal.md index 94f295568..1b0eb8270 100644 --- a/snippets/articles/s/js-object-freeze-vs-seal.md +++ b/snippets/js/s/object-freeze-vs-seal.md @@ -33,4 +33,4 @@ If you want to prevent new properties from being added and existing properties f | `Object.freeze()` | No | Yes | No | No | | `Object.seal()` | No | Yes | Yes | No | -As a closing note, remember that both methods perform a shallow freeze/seal on the object. This means that nested objects and arrays are not frozen or sealed and can be mutated. To prevent this, you can deep freeze objects, as described in [this related article](/articles/s/javascript-deep-freeze-object). +As a closing note, remember that both methods perform a shallow freeze/seal on the object. This means that nested objects and arrays are not frozen or sealed and can be mutated. To prevent this, you can deep freeze objects, as described in [this related article](/js/s/deep-freeze-object). diff --git a/snippets/js/s/has-key.md b/snippets/js/s/object-has-key.md similarity index 100% rename from snippets/js/s/has-key.md rename to snippets/js/s/object-has-key.md diff --git a/snippets/js/s/has-value.md b/snippets/js/s/object-has-value.md similarity index 100% rename from snippets/js/s/has-value.md rename to snippets/js/s/object-has-value.md diff --git a/snippets/articles/s/javascript-object-is-triple-equals.md b/snippets/js/s/object-is-triple-equals.md similarity index 100% rename from snippets/articles/s/javascript-object-is-triple-equals.md rename to snippets/js/s/object-is-triple-equals.md diff --git a/snippets/js/s/offset.md b/snippets/js/s/offset-array-elements.md similarity index 100% rename from snippets/js/s/offset.md rename to snippets/js/s/offset-array-elements.md diff --git a/snippets/js/s/omit-by.md b/snippets/js/s/omit-matching-object-keys.md similarity index 100% rename from snippets/js/s/omit-by.md rename to snippets/js/s/omit-matching-object-keys.md diff --git a/snippets/js/s/omit.md b/snippets/js/s/omit-object-keys.md similarity index 100% rename from snippets/js/s/omit.md rename to snippets/js/s/omit-object-keys.md diff --git a/snippets/js/s/order-with.md b/snippets/js/s/order-object-array-based-on-property.md similarity index 100% rename from snippets/js/s/order-with.md rename to snippets/js/s/order-object-array-based-on-property.md diff --git a/snippets/js/s/order-by.md b/snippets/js/s/order-object-array.md similarity index 100% rename from snippets/js/s/order-by.md rename to snippets/js/s/order-object-array.md diff --git a/snippets/js/s/pad.md b/snippets/js/s/pad-string.md similarity index 100% rename from snippets/js/s/pad.md rename to snippets/js/s/pad-string.md diff --git a/snippets/js/s/accumulate.md b/snippets/js/s/partial-sum-array.md similarity index 100% rename from snippets/js/s/accumulate.md rename to snippets/js/s/partial-sum-array.md diff --git a/snippets/js/s/partition.md b/snippets/js/s/partition-array-in-two.md similarity index 100% rename from snippets/js/s/partition.md rename to snippets/js/s/partition-array-in-two.md diff --git a/snippets/js/s/partition-by.md b/snippets/js/s/partition-array.md similarity index 100% rename from snippets/js/s/partition-by.md rename to snippets/js/s/partition-array.md diff --git a/snippets/articles/s/javascript-pass-by-reference-or-pass-by-value.md b/snippets/js/s/pass-by-reference-or-pass-by-value.md similarity index 100% rename from snippets/articles/s/javascript-pass-by-reference-or-pass-by-value.md rename to snippets/js/s/pass-by-reference-or-pass-by-value.md diff --git a/snippets/articles/s/passive-scroll-listener-performance.md b/snippets/js/s/passive-scroll-listener-performance.md similarity index 100% rename from snippets/articles/s/passive-scroll-listener-performance.md rename to snippets/js/s/passive-scroll-listener-performance.md diff --git a/snippets/js/s/percentile.md b/snippets/js/s/percentile-of-matches.md similarity index 100% rename from snippets/js/s/percentile.md rename to snippets/js/s/percentile-of-matches.md diff --git a/snippets/js/s/pick-by.md b/snippets/js/s/pick-matching-object-keys.md similarity index 100% rename from snippets/js/s/pick-by.md rename to snippets/js/s/pick-matching-object-keys.md diff --git a/snippets/js/s/pick.md b/snippets/js/s/pick-object-keys.md similarity index 100% rename from snippets/js/s/pick.md rename to snippets/js/s/pick-object-keys.md diff --git a/snippets/js/s/pluck.md b/snippets/js/s/pluck-values-from-object-array.md similarity index 100% rename from snippets/js/s/pluck.md rename to snippets/js/s/pluck-values-from-object-array.md diff --git a/snippets/js/s/prefix.md b/snippets/js/s/prefix-css-property.md similarity index 100% rename from snippets/js/s/prefix.md rename to snippets/js/s/prefix-css-property.md diff --git a/snippets/articles/s/javascript-prefix-postfix-operators.md b/snippets/js/s/prefix-postfix-operators.md similarity index 100% rename from snippets/articles/s/javascript-prefix-postfix-operators.md rename to snippets/js/s/prefix-postfix-operators.md diff --git a/snippets/js/s/partial.md b/snippets/js/s/prepend-function-arguments.md similarity index 100% rename from snippets/js/s/partial.md rename to snippets/js/s/prepend-function-arguments.md diff --git a/snippets/articles/s/javascript-pretty-print-json.md b/snippets/js/s/pretty-print-json.md similarity index 100% rename from snippets/articles/s/javascript-pretty-print-json.md rename to snippets/js/s/pretty-print-json.md diff --git a/snippets/js/s/pretty-bytes.md b/snippets/js/s/pretty-print-number-of-bytes.md similarity index 100% rename from snippets/js/s/pretty-bytes.md rename to snippets/js/s/pretty-print-number-of-bytes.md diff --git a/snippets/articles/s/javascript-prevent-string-being-escaped.md b/snippets/js/s/prevent-string-being-escaped.md similarity index 100% rename from snippets/articles/s/javascript-prevent-string-being-escaped.md rename to snippets/js/s/prevent-string-being-escaped.md diff --git a/snippets/articles/s/javascript-primitive-instanceof.md b/snippets/js/s/primitive-instanceof.md similarity index 100% rename from snippets/articles/s/javascript-primitive-instanceof.md rename to snippets/js/s/primitive-instanceof.md diff --git a/snippets/js/s/has-flags.md b/snippets/js/s/process-arguments-have-flags.md similarity index 100% rename from snippets/js/s/has-flags.md rename to snippets/js/s/process-arguments-have-flags.md diff --git a/snippets/js/s/prod.md b/snippets/js/s/product-of-numeric-values.md similarity index 100% rename from snippets/js/s/prod.md rename to snippets/js/s/product-of-numeric-values.md diff --git a/snippets/articles/s/javascript-promise-then-catch.md b/snippets/js/s/promise-then-catch.md similarity index 100% rename from snippets/articles/s/javascript-promise-then-catch.md rename to snippets/js/s/promise-then-catch.md diff --git a/snippets/articles/s/javascript-promise-then-finally.md b/snippets/js/s/promise-then-finally.md similarity index 100% rename from snippets/articles/s/javascript-promise-then-finally.md rename to snippets/js/s/promise-then-finally.md diff --git a/snippets/articles/s/javascript-promises.md b/snippets/js/s/promises.md similarity index 100% rename from snippets/articles/s/javascript-promises.md rename to snippets/js/s/promises.md diff --git a/snippets/articles/s/javascript-property-enumerability.md b/snippets/js/s/property-enumerability.md similarity index 100% rename from snippets/articles/s/javascript-property-enumerability.md rename to snippets/js/s/property-enumerability.md diff --git a/snippets/articles/s/js-proxy-array-negative-index.md b/snippets/js/s/proxy-array-negative-index.md similarity index 100% rename from snippets/articles/s/js-proxy-array-negative-index.md rename to snippets/js/s/proxy-array-negative-index.md diff --git a/snippets/articles/s/js-proxy-introduction.md b/snippets/js/s/proxy-introduction.md similarity index 100% rename from snippets/articles/s/js-proxy-introduction.md rename to snippets/js/s/proxy-introduction.md diff --git a/snippets/js/s/pull-at-value.md b/snippets/js/s/pull-matching-values-from-array.md similarity index 100% rename from snippets/js/s/pull-at-value.md rename to snippets/js/s/pull-matching-values-from-array.md diff --git a/snippets/js/s/pull-at-index.md b/snippets/js/s/pull-values-from-array-at-index.md similarity index 100% rename from snippets/js/s/pull-at-index.md rename to snippets/js/s/pull-values-from-array-at-index.md diff --git a/snippets/js/s/pull-by.md b/snippets/js/s/pull-values-from-array-based-on-function.md similarity index 100% rename from snippets/js/s/pull-by.md rename to snippets/js/s/pull-values-from-array-based-on-function.md diff --git a/snippets/js/s/pull.md b/snippets/js/s/pull-values-from-array.md similarity index 100% rename from snippets/js/s/pull.md rename to snippets/js/s/pull-values-from-array.md diff --git a/snippets/articles/s/javascript-pure-functions.md b/snippets/js/s/pure-functions.md similarity index 100% rename from snippets/articles/s/javascript-pure-functions.md rename to snippets/js/s/pure-functions.md diff --git a/snippets/articles/s/javascript-query-selector-shorthand.md b/snippets/js/s/query-selector-shorthand.md similarity index 100% rename from snippets/articles/s/javascript-query-selector-shorthand.md rename to snippets/js/s/query-selector-shorthand.md diff --git a/snippets/js/s/random-alpha-numeric.md b/snippets/js/s/random-alphanumeric.md similarity index 100% rename from snippets/js/s/random-alpha-numeric.md rename to snippets/js/s/random-alphanumeric.md diff --git a/snippets/js/s/random-int-array-in-range.md b/snippets/js/s/random-integer-array-in-range.md similarity index 100% rename from snippets/js/s/random-int-array-in-range.md rename to snippets/js/s/random-integer-array-in-range.md diff --git a/snippets/articles/s/javascript-random-value-pure-functions.md b/snippets/js/s/random-value-pure-functions.md similarity index 100% rename from snippets/articles/s/javascript-random-value-pure-functions.md rename to snippets/js/s/random-value-pure-functions.md diff --git a/snippets/js/s/rearg.md b/snippets/js/s/rearrange-function-arguments.md similarity index 100% rename from snippets/js/s/rearg.md rename to snippets/js/s/rearrange-function-arguments.md diff --git a/snippets/articles/s/javascript-recursion.md b/snippets/js/s/recursion.md similarity index 100% rename from snippets/articles/s/javascript-recursion.md rename to snippets/js/s/recursion.md diff --git a/snippets/js/s/redirect.md b/snippets/js/s/redirect-to-url.md similarity index 100% rename from snippets/js/s/redirect.md rename to snippets/js/s/redirect-to-url.md diff --git a/snippets/articles/s/regexp-cheatsheet.md b/snippets/js/s/regexp-cheatsheet.md similarity index 100% rename from snippets/articles/s/regexp-cheatsheet.md rename to snippets/js/s/regexp-cheatsheet.md diff --git a/snippets/js/s/reject.md b/snippets/js/s/reject-non-matching-values.md similarity index 100% rename from snippets/js/s/reject.md rename to snippets/js/s/reject-non-matching-values.md diff --git a/snippets/articles/s/javascript-reload-page.md b/snippets/js/s/reload-page.md similarity index 100% rename from snippets/articles/s/javascript-reload-page.md rename to snippets/js/s/reload-page.md diff --git a/snippets/articles/s/js-remove-array-duplicates.md b/snippets/js/s/remove-array-duplicates.md similarity index 100% rename from snippets/articles/s/js-remove-array-duplicates.md rename to snippets/js/s/remove-array-duplicates.md diff --git a/snippets/js/s/remove-class.md b/snippets/js/s/remove-class-from-html-element.md similarity index 100% rename from snippets/js/s/remove-class.md rename to snippets/js/s/remove-class-from-html-element.md diff --git a/snippets/js/s/remove-element.md b/snippets/js/s/remove-dom-element.md similarity index 100% rename from snippets/js/s/remove-element.md rename to snippets/js/s/remove-dom-element.md diff --git a/snippets/articles/s/js-remove-element-from-array.md b/snippets/js/s/remove-element-from-array.md similarity index 94% rename from snippets/articles/s/js-remove-element-from-array.md rename to snippets/js/s/remove-element-from-array.md index adf0c2b7d..d407b82a1 100644 --- a/snippets/articles/s/js-remove-element-from-array.md +++ b/snippets/js/s/remove-element-from-array.md @@ -40,5 +40,5 @@ Most of the time, `Array.prototype.filter()` is the best option for removing ele ### Alternative options -The previous two options should cover the vast majority of use cases. Yet, there are some other options available for removing elements from an array, which might be preferable in certain cases. For example, if you like the interface of `Array.prototype.splice()` but need immutability, the [shank snippet](/js/s/shank) might be the solution for you. Similarly, when working with large unsorted arrays, there's a [fast removal trick](/articles/s/js-fast-remove-array-element) that might be of interest to you. +The previous two options should cover the vast majority of use cases. Yet, there are some other options available for removing elements from an array, which might be preferable in certain cases. For example, if you like the interface of `Array.prototype.splice()` but need immutability, the [shank snippet](/js/s/shank) might be the solution for you. Similarly, when working with large unsorted arrays, there's a [fast removal trick](/js/s/fast-remove-array-element) that might be of interest to you. diff --git a/snippets/js/s/shank.md b/snippets/js/s/remove-elements-from-array.md similarity index 100% rename from snippets/js/s/shank.md rename to snippets/js/s/remove-elements-from-array.md diff --git a/snippets/js/s/off.md b/snippets/js/s/remove-event-listener.md similarity index 100% rename from snippets/js/s/off.md rename to snippets/js/s/remove-event-listener.md diff --git a/snippets/js/s/remove.md b/snippets/js/s/remove-matching-array-elements.md similarity index 100% rename from snippets/js/s/remove.md rename to snippets/js/s/remove-matching-array-elements.md diff --git a/snippets/js/s/remove-event-listener-all.md b/snippets/js/s/remove-multiple-event-listeners.md similarity index 100% rename from snippets/js/s/remove-event-listener-all.md rename to snippets/js/s/remove-multiple-event-listeners.md diff --git a/snippets/articles/s/javascript-remove-object-property.md b/snippets/js/s/remove-object-property.md similarity index 100% rename from snippets/articles/s/javascript-remove-object-property.md rename to snippets/js/s/remove-object-property.md diff --git a/snippets/articles/s/js-remove-trailing-zeros.md b/snippets/js/s/remove-trailing-zeros.md similarity index 100% rename from snippets/articles/s/js-remove-trailing-zeros.md rename to snippets/js/s/remove-trailing-zeros.md diff --git a/snippets/js/s/rename-keys.md b/snippets/js/s/rename-object-keys.md similarity index 100% rename from snippets/js/s/rename-keys.md rename to snippets/js/s/rename-object-keys.md diff --git a/snippets/js/s/render-element.md b/snippets/js/s/render-dom-element.md similarity index 100% rename from snippets/js/s/render-element.md rename to snippets/js/s/render-dom-element.md diff --git a/snippets/articles/s/js-replace-all-occurences-of-string.md b/snippets/js/s/replace-all-occurences-of-string.md similarity index 100% rename from snippets/articles/s/js-replace-all-occurences-of-string.md rename to snippets/js/s/replace-all-occurences-of-string.md diff --git a/snippets/js/s/replace-last.md b/snippets/js/s/replace-last-occurrence.md similarity index 100% rename from snippets/js/s/replace-last.md rename to snippets/js/s/replace-last-occurrence.md diff --git a/snippets/js/s/replace-or-append.md b/snippets/js/s/replace-or-append-array-value.md similarity index 100% rename from snippets/js/s/replace-or-append.md rename to snippets/js/s/replace-or-append-array-value.md diff --git a/snippets/js/s/resolve-after.md b/snippets/js/s/resolve-promise-after-amount-of-time.md similarity index 100% rename from snippets/js/s/resolve-after.md rename to snippets/js/s/resolve-promise-after-amount-of-time.md diff --git a/snippets/articles/s/javascript-return-constructor.md b/snippets/js/s/return-constructor.md similarity index 100% rename from snippets/articles/s/javascript-return-constructor.md rename to snippets/js/s/return-constructor.md diff --git a/snippets/js/s/compose-right.md b/snippets/js/s/reverse-compose-functions.md similarity index 100% rename from snippets/js/s/compose-right.md rename to snippets/js/s/reverse-compose-functions.md diff --git a/snippets/js/s/for-own-right.md b/snippets/js/s/reverse-iterate-object-properties.md similarity index 100% rename from snippets/js/s/for-own-right.md rename to snippets/js/s/reverse-iterate-object-properties.md diff --git a/snippets/js/s/right-substr-generator.md b/snippets/js/s/right-substring-generator.md similarity index 100% rename from snippets/js/s/right-substr-generator.md rename to snippets/js/s/right-substring-generator.md diff --git a/snippets/js/s/round.md b/snippets/js/s/round-number-to-precision.md similarity index 100% rename from snippets/js/s/round.md rename to snippets/js/s/round-number-to-precision.md diff --git a/snippets/js/s/run-async.md b/snippets/js/s/run-function-asyc.md similarity index 100% rename from snippets/js/s/run-async.md rename to snippets/js/s/run-function-asyc.md diff --git a/snippets/articles/s/select-focused-dom-element.md b/snippets/js/s/select-focused-dom-element.md similarity index 100% rename from snippets/articles/s/select-focused-dom-element.md rename to snippets/js/s/select-focused-dom-element.md diff --git a/snippets/js/s/set-style.md b/snippets/js/s/set-style-for-html-element.md similarity index 100% rename from snippets/js/s/set-style.md rename to snippets/js/s/set-style-for-html-element.md diff --git a/snippets/js/s/shallow-clone.md b/snippets/js/s/shallow-clone-object.md similarity index 100% rename from snippets/js/s/shallow-clone.md rename to snippets/js/s/shallow-clone-object.md diff --git a/snippets/articles/s/javascript-shallow-deep-clone.md b/snippets/js/s/shallow-deep-clone.md similarity index 100% rename from snippets/articles/s/javascript-shallow-deep-clone.md rename to snippets/js/s/shallow-deep-clone.md diff --git a/snippets/js/s/show.md b/snippets/js/s/show-html-elements.md similarity index 100% rename from snippets/js/s/show.md rename to snippets/js/s/show-html-elements.md diff --git a/snippets/articles/s/javascript-singleton-proxy.md b/snippets/js/s/singleton-proxy.md similarity index 100% rename from snippets/articles/s/javascript-singleton-proxy.md rename to snippets/js/s/singleton-proxy.md diff --git a/snippets/js/s/size.md b/snippets/js/s/size-of-array-object-or-string.md similarity index 100% rename from snippets/js/s/size.md rename to snippets/js/s/size-of-array-object-or-string.md diff --git a/snippets/js/s/sleep.md b/snippets/js/s/sleep.md index 3a6b61d4a..635fb44bc 100644 --- a/snippets/js/s/sleep.md +++ b/snippets/js/s/sleep.md @@ -1,24 +1,65 @@ --- -title: Delay async function execution -type: snippet +title: How can I implement a sleep function in JavaScript? +shortTitle: Sleep function +type: question language: javascript -tags: [function,promise] +tags: [date,promise] +author: chalarangelo cover: sleepy-cat -dateModified: 2020-10-22T20:24:30+03:00 +excerpt: Learn all the different ways you can implement a `sleep()` function in JavaScript. +dateModified: 2021-11-06T20:51:47+03:00 --- -Delays the execution of an asynchronous function. +JavaScript does not come with a `sleep()` function out of the box. That's probably a good idea considering the environments where it runs and the trouble it could cause if used incorrectly. The closest equivalent is the `setTimeout()` function, but there are other, less common ways to implement a function that will pause execution for a specified amount of time. -- Delay executing part of an `async` function, by putting it to sleep, returning a `Promise`. +### setTimeout + +JavaScript's `setTimeout()` sets a timer which executes some code once the timer expires. Only the code inside the `setTimeout()` callback will execute after the timer expires. This can lead to nesting issues, as well as code executing out of order if you are not careful. ```js -const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); +const printNums = () => { + console.log(1); + setTimeout(() => console.log(2), 500); + console.log(3); +}; + +printNums(); // Logs: 1, 3, 2 (2 logs after 500ms) ``` +### Synchronous version + +While strongly discouraged, `Date.prototype.getTime()` can be used inside a `while` loop to pause execution for a set amount of time. You can easily define a synchronous `sleep()` function like this: + ```js -async function sleepyWork() { - console.log("I'm going to sleep for 1 second."); - await sleep(1000); - console.log('I woke up after 1 second.'); +const sleepSync = (ms) => { + const end = new Date().getTime() + ms; + while (new Date().getTime() < end) { /* do nothing */ } } + +const printNums = () => { + console.log(1); + sleepSync(500); + console.log(2); + console.log(3); +}; + +printNums(); // Logs: 1, 2, 3 (2 and 3 log after 500ms) +``` + +### Asynchronous version + +A less intrusive way to go about implementing a `sleep()` function is to utilize the `async` and `await` keywords added in JavaScript ES6, a `Promise` and `setTimeout()`. Note that the resulting function must be executed in an `async` function and has to be called with `await`: + +```js +const sleep = (ms) => + new Promise(resolve => setTimeout(resolve, ms)); + +const printNums = async() => { + console.log(1); + await sleep(500); + console.log(2); + console.log(3); +}; + +printNums(); // Logs: 1, 2, 3 (2 and 3 log after 500ms) ``` diff --git a/snippets/js/s/alphabetical.md b/snippets/js/s/sort-array-alphabetically.md similarity index 100% rename from snippets/js/s/alphabetical.md rename to snippets/js/s/sort-array-alphabetically.md diff --git a/snippets/js/s/chunk-into-n.md b/snippets/js/s/split-array-into-n-chunks.md similarity index 100% rename from snippets/js/s/chunk-into-n.md rename to snippets/js/s/split-array-into-n-chunks.md diff --git a/snippets/js/s/chunk.md b/snippets/js/s/split-into-chunks.md similarity index 100% rename from snippets/js/s/chunk.md rename to snippets/js/s/split-into-chunks.md diff --git a/snippets/js/s/split-lines.md b/snippets/js/s/split-into-lines.md similarity index 100% rename from snippets/js/s/split-lines.md rename to snippets/js/s/split-into-lines.md diff --git a/snippets/articles/s/js-spread-operator-tricks.md b/snippets/js/s/spread-operator-tricks.md similarity index 100% rename from snippets/articles/s/js-spread-operator-tricks.md rename to snippets/js/s/spread-operator-tricks.md diff --git a/snippets/articles/s/javascript-spread-rest-syntax.md b/snippets/js/s/spread-rest-syntax.md similarity index 100% rename from snippets/articles/s/javascript-spread-rest-syntax.md rename to snippets/js/s/spread-rest-syntax.md diff --git a/snippets/articles/s/js-static-instance-methods.md b/snippets/js/s/static-instance-methods.md similarity index 100% rename from snippets/articles/s/js-static-instance-methods.md rename to snippets/js/s/static-instance-methods.md diff --git a/snippets/articles/s/javascript-store-dom-items.md b/snippets/js/s/store-dom-items.md similarity index 100% rename from snippets/articles/s/javascript-store-dom-items.md rename to snippets/js/s/store-dom-items.md diff --git a/snippets/articles/s/javascript-string-contains-substring.md b/snippets/js/s/string-contains-substring.md similarity index 100% rename from snippets/articles/s/javascript-string-contains-substring.md rename to snippets/js/s/string-contains-substring.md diff --git a/snippets/articles/s/javascript-string-immutability.md b/snippets/js/s/string-immutability.md similarity index 100% rename from snippets/articles/s/javascript-string-immutability.md rename to snippets/js/s/string-immutability.md diff --git a/snippets/articles/s/javascript-string-to-boolean.md b/snippets/js/s/string-to-boolean.md similarity index 100% rename from snippets/articles/s/javascript-string-to-boolean.md rename to snippets/js/s/string-to-boolean.md diff --git a/snippets/js/s/slugify.md b/snippets/js/s/string-to-slug.md similarity index 100% rename from snippets/js/s/slugify.md rename to snippets/js/s/string-to-slug.md diff --git a/snippets/js/s/words.md b/snippets/js/s/string-to-words.md similarity index 100% rename from snippets/js/s/words.md rename to snippets/js/s/string-to-words.md diff --git a/snippets/js/s/sub-set.md b/snippets/js/s/subset.md similarity index 100% rename from snippets/js/s/sub-set.md rename to snippets/js/s/subset.md diff --git a/snippets/js/s/reduce-successive.md b/snippets/js/s/successive-values-array.md similarity index 100% rename from snippets/js/s/reduce-successive.md rename to snippets/js/s/successive-values-array.md diff --git a/snippets/js/s/sum.md b/snippets/js/s/sum-array.md similarity index 100% rename from snippets/js/s/sum.md rename to snippets/js/s/sum-array.md diff --git a/snippets/js/s/sum-n.md b/snippets/js/s/sum-of-numbers-until-n.md similarity index 100% rename from snippets/js/s/sum-n.md rename to snippets/js/s/sum-of-numbers-until-n.md diff --git a/snippets/js/s/sum-power.md b/snippets/js/s/sum-powers-in-range.md similarity index 100% rename from snippets/js/s/sum-power.md rename to snippets/js/s/sum-powers-in-range.md diff --git a/snippets/js/s/super-set.md b/snippets/js/s/superset.md similarity index 100% rename from snippets/js/s/super-set.md rename to snippets/js/s/superset.md diff --git a/snippets/articles/s/javascript-swap-two-variables.md b/snippets/js/s/swap-two-variables.md similarity index 100% rename from snippets/articles/s/javascript-swap-two-variables.md rename to snippets/js/s/swap-two-variables.md diff --git a/snippets/articles/s/javascript-switch-object.md b/snippets/js/s/switch-object.md similarity index 100% rename from snippets/articles/s/javascript-switch-object.md rename to snippets/js/s/switch-object.md diff --git a/snippets/js/s/symbolize-keys.md b/snippets/js/s/symbolize-object-keys.md similarity index 100% rename from snippets/js/s/symbolize-keys.md rename to snippets/js/s/symbolize-object-keys.md diff --git a/snippets/articles/s/javascript-sync-async.md b/snippets/js/s/sync-async.md similarity index 100% rename from snippets/articles/s/javascript-sync-async.md rename to snippets/js/s/sync-async.md diff --git a/snippets/js/s/take-right-until.md b/snippets/js/s/take-array-elements-from-end-until.md similarity index 93% rename from snippets/js/s/take-right-until.md rename to snippets/js/s/take-array-elements-from-end-until.md index 6c5f193de..c05013625 100644 --- a/snippets/js/s/take-right-until.md +++ b/snippets/js/s/take-array-elements-from-end-until.md @@ -1,5 +1,5 @@ --- -title: Remove list elements from the end until condition is met +title: Remove array elements from the end until condition is met type: snippet language: javascript tags: [array] diff --git a/snippets/js/s/take-right-while.md b/snippets/js/s/take-array-elements-from-end-while.md similarity index 93% rename from snippets/js/s/take-right-while.md rename to snippets/js/s/take-array-elements-from-end-while.md index dff82e163..0f345b9ef 100644 --- a/snippets/js/s/take-right-while.md +++ b/snippets/js/s/take-array-elements-from-end-while.md @@ -1,5 +1,5 @@ --- -title: Remove list elements from the end while condition is met +title: Remove array elements from the end while condition is met type: snippet language: javascript tags: [array] diff --git a/snippets/js/s/take-right.md b/snippets/js/s/take-array-elements-from-end.md similarity index 91% rename from snippets/js/s/take-right.md rename to snippets/js/s/take-array-elements-from-end.md index fb899c676..fc6d20c93 100644 --- a/snippets/js/s/take-right.md +++ b/snippets/js/s/take-array-elements-from-end.md @@ -1,5 +1,5 @@ --- -title: Remove list elements from the end +title: Remove array elements from the end type: snippet language: javascript tags: [array] diff --git a/snippets/js/s/take-until.md b/snippets/js/s/take-array-elements-until.md similarity index 93% rename from snippets/js/s/take-until.md rename to snippets/js/s/take-array-elements-until.md index 60c46549d..3ee69d7fc 100644 --- a/snippets/js/s/take-until.md +++ b/snippets/js/s/take-array-elements-until.md @@ -1,5 +1,5 @@ --- -title: Remove list elements until condition is met +title: Remove array elements until condition is met type: snippet language: javascript tags: [array] diff --git a/snippets/js/s/take-while.md b/snippets/js/s/take-array-elements-while.md similarity index 93% rename from snippets/js/s/take-while.md rename to snippets/js/s/take-array-elements-while.md index 04926e8c8..10a94dcbc 100644 --- a/snippets/js/s/take-while.md +++ b/snippets/js/s/take-array-elements-while.md @@ -1,5 +1,5 @@ --- -title: Remove list elements while condition is met +title: Remove array elements while condition is met type: snippet language: javascript tags: [array] diff --git a/snippets/js/s/take.md b/snippets/js/s/take-array-elements.md similarity index 93% rename from snippets/js/s/take.md rename to snippets/js/s/take-array-elements.md index 117df51df..4e3b21c81 100644 --- a/snippets/js/s/take.md +++ b/snippets/js/s/take-array-elements.md @@ -1,5 +1,5 @@ --- -title: Remove list elements +title: Remove array elements type: snippet language: javascript tags: [array] diff --git a/snippets/articles/s/javascript-target-blank.md b/snippets/js/s/target-blank.md similarity index 100% rename from snippets/articles/s/javascript-target-blank.md rename to snippets/js/s/target-blank.md diff --git a/snippets/articles/s/javascript-ternary-operator.md b/snippets/js/s/ternary-operator.md similarity index 100% rename from snippets/articles/s/javascript-ternary-operator.md rename to snippets/js/s/ternary-operator.md diff --git a/snippets/articles/s/js-textcontent-or-innertext.md b/snippets/js/s/textcontent-or-innertext.md similarity index 100% rename from snippets/articles/s/js-textcontent-or-innertext.md rename to snippets/js/s/textcontent-or-innertext.md diff --git a/snippets/articles/s/the-case-for-javascript-trailing-commas.md b/snippets/js/s/the-case-for-trailing-commas.md similarity index 100% rename from snippets/articles/s/the-case-for-javascript-trailing-commas.md rename to snippets/js/s/the-case-for-trailing-commas.md diff --git a/snippets/articles/s/javascript-this.md b/snippets/js/s/this.md similarity index 100% rename from snippets/articles/s/javascript-this.md rename to snippets/js/s/this.md diff --git a/snippets/js/s/throttle.md b/snippets/js/s/throttle-function.md similarity index 100% rename from snippets/js/s/throttle.md rename to snippets/js/s/throttle-function.md diff --git a/snippets/articles/s/js-timeout-interval-delay.md b/snippets/js/s/timeout-interval-delay.md similarity index 70% rename from snippets/articles/s/js-timeout-interval-delay.md rename to snippets/js/s/timeout-interval-delay.md index a9e3f924c..56b70e42e 100644 --- a/snippets/articles/s/js-timeout-interval-delay.md +++ b/snippets/js/s/timeout-interval-delay.md @@ -14,7 +14,7 @@ JavaScript provides two widely used timing functions, `setTimeout()` and `setInt ### Delays are not exact -I went into detail about how JavaScript engines execute code in [the Event Loop explanation](/articles/s/javascript-event-loop-explained), but let me recap here. As JavaScript is single-threaded, tasks are queued to be executed in a loop. Thus, `setTimeout()` and `setInterval()` are tasks that will be executed after at least the given amount of time has elapsed. There is no guarantee, however, that the task will be executed exactly after the given amount of time has elapsed. The delay is a suggestion, signifying the **minimum amount of time** that must pass before the task is executed. The actual delay can be longer, depending on the current state of the JavaScript engine. +I went into detail about how JavaScript engines execute code in [the Event Loop explanation](/js/s/event-loop-explained), but let me recap here. As JavaScript is single-threaded, tasks are queued to be executed in a loop. Thus, `setTimeout()` and `setInterval()` are tasks that will be executed after at least the given amount of time has elapsed. There is no guarantee, however, that the task will be executed exactly after the given amount of time has elapsed. The delay is a suggestion, signifying the **minimum amount of time** that must pass before the task is executed. The actual delay can be longer, depending on the current state of the JavaScript engine. ### Browser factors diff --git a/snippets/js/s/to-char-array.md b/snippets/js/s/to-character-array.md similarity index 100% rename from snippets/js/s/to-char-array.md rename to snippets/js/s/to-character-array.md diff --git a/snippets/js/s/flags.md b/snippets/js/s/to-flags-object.md similarity index 100% rename from snippets/js/s/flags.md rename to snippets/js/s/to-flags-object.md diff --git a/snippets/js/s/toggle-element.md b/snippets/js/s/toggle-array-element.md similarity index 100% rename from snippets/js/s/toggle-element.md rename to snippets/js/s/toggle-array-element.md diff --git a/snippets/js/s/toggle-class.md b/snippets/js/s/toggle-html-element-class.md similarity index 100% rename from snippets/js/s/toggle-class.md rename to snippets/js/s/toggle-html-element-class.md diff --git a/snippets/js/s/over-args.md b/snippets/js/s/transform-function-arguments.md similarity index 100% rename from snippets/js/s/over-args.md rename to snippets/js/s/transform-function-arguments.md diff --git a/snippets/js/s/transform.md b/snippets/js/s/transform-object.md similarity index 100% rename from snippets/js/s/transform.md rename to snippets/js/s/transform-object.md diff --git a/snippets/js/s/transpose.md b/snippets/js/s/transpose-matrix.md similarity index 100% rename from snippets/js/s/transpose.md rename to snippets/js/s/transpose-matrix.md diff --git a/snippets/articles/s/javascript-truthy-falsy-values.md b/snippets/js/s/truthy-falsy-values.md similarity index 100% rename from snippets/articles/s/javascript-truthy-falsy-values.md rename to snippets/js/s/truthy-falsy-values.md diff --git a/snippets/js/s/get-type.md b/snippets/js/s/type-of-value.md similarity index 100% rename from snippets/js/s/get-type.md rename to snippets/js/s/type-of-value.md diff --git a/snippets/articles/s/js-typecheck-array.md b/snippets/js/s/typecheck-array.md similarity index 100% rename from snippets/articles/s/js-typecheck-array.md rename to snippets/js/s/typecheck-array.md diff --git a/snippets/articles/s/js-typecheck-proxy.md b/snippets/js/s/typecheck-proxy.md similarity index 100% rename from snippets/articles/s/js-typecheck-proxy.md rename to snippets/js/s/typecheck-proxy.md diff --git a/snippets/js/s/unary.md b/snippets/js/s/unary-function-arity.md similarity index 100% rename from snippets/js/s/unary.md rename to snippets/js/s/unary-function-arity.md diff --git a/snippets/js/s/require-uncached.md b/snippets/js/s/uncached-module-require.md similarity index 100% rename from snippets/js/s/require-uncached.md rename to snippets/js/s/uncached-module-require.md diff --git a/snippets/js/s/uncurry.md b/snippets/js/s/uncurry-function.md similarity index 100% rename from snippets/js/s/uncurry.md rename to snippets/js/s/uncurry-function.md diff --git a/snippets/articles/s/javascript-undeclared-undefined-null.md b/snippets/js/s/undeclared-undefined-null.md similarity index 100% rename from snippets/articles/s/javascript-undeclared-undefined-null.md rename to snippets/js/s/undeclared-undefined-null.md diff --git a/snippets/js/s/unfold.md b/snippets/js/s/unfold-array.md similarity index 100% rename from snippets/js/s/unfold.md rename to snippets/js/s/unfold-array.md diff --git a/snippets/js/s/unzip-with.md b/snippets/js/s/ungroup-array-elements-based-on-function.md similarity index 100% rename from snippets/js/s/unzip-with.md rename to snippets/js/s/ungroup-array-elements-based-on-function.md diff --git a/snippets/js/s/unzip.md b/snippets/js/s/ungroup-array-elements.md similarity index 100% rename from snippets/js/s/unzip.md rename to snippets/js/s/ungroup-array-elements.md diff --git a/snippets/js/s/unique-elements.md b/snippets/js/s/unique-elements-in-array.md similarity index 100% rename from snippets/js/s/unique-elements.md rename to snippets/js/s/unique-elements-in-array.md diff --git a/snippets/js/s/get-timestamp.md b/snippets/js/s/unix-timestamp-from-date.md similarity index 100% rename from snippets/js/s/get-timestamp.md rename to snippets/js/s/unix-timestamp-from-date.md diff --git a/snippets/js/s/unwind.md b/snippets/js/s/unwind-object.md similarity index 100% rename from snippets/js/s/unwind.md rename to snippets/js/s/unwind-object.md diff --git a/snippets/articles/s/javascript-use-strict.md b/snippets/js/s/use-strict.md similarity index 100% rename from snippets/articles/s/javascript-use-strict.md rename to snippets/js/s/use-strict.md diff --git a/snippets/articles/s/javascript-value-as-number.md b/snippets/js/s/value-as-number.md similarity index 100% rename from snippets/articles/s/javascript-value-as-number.md rename to snippets/js/s/value-as-number.md diff --git a/snippets/js/s/frequencies.md b/snippets/js/s/value-frequencies.md similarity index 100% rename from snippets/js/s/frequencies.md rename to snippets/js/s/value-frequencies.md diff --git a/snippets/js/s/is.md b/snippets/js/s/value-is-of-type.md similarity index 100% rename from snippets/js/s/is.md rename to snippets/js/s/value-is-of-type.md diff --git a/snippets/articles/s/javascript-value-not-equal-to-itself.md b/snippets/js/s/value-not-equal-to-itself.md similarity index 100% rename from snippets/articles/s/javascript-value-not-equal-to-itself.md rename to snippets/js/s/value-not-equal-to-itself.md diff --git a/snippets/articles/s/javascript-var-let-const.md b/snippets/js/s/var-let-const.md similarity index 91% rename from snippets/articles/s/javascript-var-let-const.md rename to snippets/js/s/var-let-const.md index 0a362e925..ac63c2022 100644 --- a/snippets/articles/s/javascript-var-let-const.md +++ b/snippets/js/s/var-let-const.md @@ -33,7 +33,7 @@ const scopeExample = () => { }; ``` -If you want to learn more, we have [an article covering JavaScript variables and scopes in more depth](/articles/s/javascript-variable-scope). +If you want to learn more, we have [an article covering JavaScript variables and scopes in more depth](/js/s/variable-scope). ### Hoisting @@ -51,7 +51,7 @@ const hoistingExample = () => { }; ``` -If you want to learn more, we have [an article covering JavaScript hoisting in more depth](/articles/s/javascript-variable-hoisting). +If you want to learn more, we have [an article covering JavaScript hoisting in more depth](/js/s/variable-hoisting). ### Global object property @@ -78,4 +78,4 @@ let b = 'let1'; let b = 'let2'; // SyntaxError ``` -If you want to learn more, we have [an article covering JavaScript's strict mode in more depth](/articles/s/javascript-use-strict). +If you want to learn more, we have [an article covering JavaScript's strict mode in more depth](/js/s/use-strict). diff --git a/snippets/articles/s/javascript-variable-hoisting.md b/snippets/js/s/variable-hoisting.md similarity index 100% rename from snippets/articles/s/javascript-variable-hoisting.md rename to snippets/js/s/variable-hoisting.md diff --git a/snippets/articles/s/javascript-variable-scope.md b/snippets/js/s/variable-scope.md similarity index 100% rename from snippets/articles/s/javascript-variable-scope.md rename to snippets/js/s/variable-scope.md diff --git a/snippets/articles/s/javascript-void-links.md b/snippets/js/s/void-links.md similarity index 100% rename from snippets/articles/s/javascript-void-links.md rename to snippets/js/s/void-links.md diff --git a/snippets/js/s/walk-through.md b/snippets/js/s/walk-through-object.md similarity index 100% rename from snippets/js/s/walk-through.md rename to snippets/js/s/walk-through-object.md diff --git a/snippets/articles/s/js-window-location-cheatsheet.md b/snippets/js/s/window-location-cheatsheet.md similarity index 100% rename from snippets/articles/s/js-window-location-cheatsheet.md rename to snippets/js/s/window-location-cheatsheet.md diff --git a/snippets/articles/s/6-python-f-strings-tips.md b/snippets/python/s/6-f-strings-tips.md similarity index 100% rename from snippets/articles/s/6-python-f-strings-tips.md rename to snippets/python/s/6-f-strings-tips.md diff --git a/snippets/articles/s/python-bare-except.md b/snippets/python/s/bare-except.md similarity index 100% rename from snippets/articles/s/python-bare-except.md rename to snippets/python/s/bare-except.md diff --git a/snippets/articles/s/code-anatomy-performant-python.md b/snippets/python/s/code-anatomy-performant-python.md similarity index 100% rename from snippets/articles/s/code-anatomy-performant-python.md rename to snippets/python/s/code-anatomy-performant-python.md diff --git a/snippets/articles/s/python-dict-getkey-vs-dictkey.md b/snippets/python/s/dict-getkey-vs-dictkey.md similarity index 100% rename from snippets/articles/s/python-dict-getkey-vs-dictkey.md rename to snippets/python/s/dict-getkey-vs-dictkey.md diff --git a/snippets/articles/s/python-empty-list.md b/snippets/python/s/empty-list.md similarity index 100% rename from snippets/articles/s/python-empty-list.md rename to snippets/python/s/empty-list.md diff --git a/snippets/articles/s/python-file-close.md b/snippets/python/s/file-close.md similarity index 100% rename from snippets/articles/s/python-file-close.md rename to snippets/python/s/file-close.md diff --git a/snippets/articles/s/python-fstrings-str-format.md b/snippets/python/s/fstrings-str-format.md similarity index 100% rename from snippets/articles/s/python-fstrings-str-format.md rename to snippets/python/s/fstrings-str-format.md diff --git a/snippets/articles/s/python-identity-equality.md b/snippets/python/s/identity-equality.md similarity index 100% rename from snippets/articles/s/python-identity-equality.md rename to snippets/python/s/identity-equality.md diff --git a/snippets/articles/s/python-lists-tuples.md b/snippets/python/s/lists-tuples.md similarity index 100% rename from snippets/articles/s/python-lists-tuples.md rename to snippets/python/s/lists-tuples.md diff --git a/snippets/articles/s/python-lowercase.md b/snippets/python/s/lowercase.md similarity index 100% rename from snippets/articles/s/python-lowercase.md rename to snippets/python/s/lowercase.md diff --git a/snippets/articles/s/python-mutable-default-arguments.md b/snippets/python/s/mutable-default-arguments.md similarity index 100% rename from snippets/articles/s/python-mutable-default-arguments.md rename to snippets/python/s/mutable-default-arguments.md diff --git a/snippets/articles/s/python-named-tuples.md b/snippets/python/s/named-tuples.md similarity index 100% rename from snippets/articles/s/python-named-tuples.md rename to snippets/python/s/named-tuples.md diff --git a/snippets/articles/s/setup-python3-pip3-as-default.md b/snippets/python/s/setup-python3-pip3-as-default.md similarity index 100% rename from snippets/articles/s/setup-python3-pip3-as-default.md rename to snippets/python/s/setup-python3-pip3-as-default.md diff --git a/snippets/articles/s/python-slice-assignment.md b/snippets/python/s/slice-assignment.md similarity index 100% rename from snippets/articles/s/python-slice-assignment.md rename to snippets/python/s/slice-assignment.md diff --git a/snippets/articles/s/python-slice-notation.md b/snippets/python/s/slice-notation.md similarity index 100% rename from snippets/articles/s/python-slice-notation.md rename to snippets/python/s/slice-notation.md diff --git a/snippets/articles/s/python-sort-dictionary-tuple-key.md b/snippets/python/s/sort-dictionary-tuple-key.md similarity index 100% rename from snippets/articles/s/python-sort-dictionary-tuple-key.md rename to snippets/python/s/sort-dictionary-tuple-key.md diff --git a/snippets/articles/s/python-sortedlist-vs-list-sort.md b/snippets/python/s/sortedlist-vs-list-sort.md similarity index 100% rename from snippets/articles/s/python-sortedlist-vs-list-sort.md rename to snippets/python/s/sortedlist-vs-list-sort.md diff --git a/snippets/articles/s/python-string-is-empty.md b/snippets/python/s/string-is-empty.md similarity index 100% rename from snippets/articles/s/python-string-is-empty.md rename to snippets/python/s/string-is-empty.md diff --git a/snippets/articles/s/python-swap-variables.md b/snippets/python/s/swap-variables.md similarity index 100% rename from snippets/articles/s/python-swap-variables.md rename to snippets/python/s/swap-variables.md diff --git a/snippets/articles/s/python-trim-whitespace.md b/snippets/python/s/trim-whitespace.md similarity index 100% rename from snippets/articles/s/python-trim-whitespace.md rename to snippets/python/s/trim-whitespace.md diff --git a/snippets/articles/s/breaking-react.md b/snippets/react/s/breaking-react.md similarity index 100% rename from snippets/articles/s/breaking-react.md rename to snippets/react/s/breaking-react.md diff --git a/snippets/articles/s/react-conditional-classname.md b/snippets/react/s/conditional-classname.md similarity index 100% rename from snippets/articles/s/react-conditional-classname.md rename to snippets/react/s/conditional-classname.md diff --git a/snippets/articles/s/react-proptypes-objectof-vs-shape.md b/snippets/react/s/proptypes-objectof-vs-shape.md similarity index 100% rename from snippets/articles/s/react-proptypes-objectof-vs-shape.md rename to snippets/react/s/proptypes-objectof-vs-shape.md diff --git a/snippets/articles/s/react-redux-readable-reducers.md b/snippets/react/s/redux-readable-reducers.md similarity index 100% rename from snippets/articles/s/react-redux-readable-reducers.md rename to snippets/react/s/redux-readable-reducers.md diff --git a/snippets/articles/s/react-rendering-basics.md b/snippets/react/s/rendering-basics.md similarity index 100% rename from snippets/articles/s/react-rendering-basics.md rename to snippets/react/s/rendering-basics.md diff --git a/snippets/articles/s/react-rendering-optimization.md b/snippets/react/s/rendering-optimization.md similarity index 100% rename from snippets/articles/s/react-rendering-optimization.md rename to snippets/react/s/rendering-optimization.md diff --git a/snippets/articles/s/react-rendering-state.md b/snippets/react/s/rendering-state.md similarity index 100% rename from snippets/articles/s/react-rendering-state.md rename to snippets/react/s/rendering-state.md diff --git a/snippets/articles/s/react-selected-option.md b/snippets/react/s/selected-option.md similarity index 100% rename from snippets/articles/s/react-selected-option.md rename to snippets/react/s/selected-option.md diff --git a/snippets/articles/s/testing-async-react-components.md b/snippets/react/s/testing-async-components.md similarity index 100% rename from snippets/articles/s/testing-async-react-components.md rename to snippets/react/s/testing-async-components.md diff --git a/snippets/articles/s/testing-react-portals.md b/snippets/react/s/testing-portals.md similarity index 100% rename from snippets/articles/s/testing-react-portals.md rename to snippets/react/s/testing-portals.md diff --git a/snippets/articles/s/testing-redux-connected-components.md b/snippets/react/s/testing-redux-connected-components.md similarity index 100% rename from snippets/articles/s/testing-redux-connected-components.md rename to snippets/react/s/testing-redux-connected-components.md diff --git a/snippets/articles/s/testing-stateful-ui-components.md b/snippets/react/s/testing-stateful-ui-components.md similarity index 100% rename from snippets/articles/s/testing-stateful-ui-components.md rename to snippets/react/s/testing-stateful-ui-components.md diff --git a/snippets/articles/s/react-use-effect-primitive-dependencies.md b/snippets/react/s/use-effect-primitive-dependencies.md similarity index 88% rename from snippets/articles/s/react-use-effect-primitive-dependencies.md rename to snippets/react/s/use-effect-primitive-dependencies.md index 4c2757226..50e1d97f4 100644 --- a/snippets/articles/s/react-use-effect-primitive-dependencies.md +++ b/snippets/react/s/use-effect-primitive-dependencies.md @@ -12,7 +12,7 @@ dateModified: 2022-06-12T05:00:00-04:00 Conditionally firing an effect is a pretty common requirement when working with React. In most cases, this is as simple as passing a dependency array to `useEffect()`. Turns out that, in some cases, this can cause unnecessary performance degradation. -Such issues arise when entire objects are passed as dependencies when you only need a primitive value. Due to the nature of objects, [being pass-by-reference](/articles/s/javascript-pass-by-reference-or-pass-by-value), comparing the dependencies will always trigger a re-run. This ends up causing effects to run unnecessarily. +Such issues arise when entire objects are passed as dependencies when you only need a primitive value. Due to the nature of objects, [being pass-by-reference](/js/s/pass-by-reference-or-pass-by-value), comparing the dependencies will always trigger a re-run. This ends up causing effects to run unnecessarily. ```jsx const CartItem = ({ item }) => { diff --git a/snippets/articles/s/react-use-interval-explained.md b/snippets/react/s/use-interval-explained.md similarity index 100% rename from snippets/articles/s/react-use-interval-explained.md rename to snippets/react/s/use-interval-explained.md diff --git a/snippets/articles/s/react-use-state-with-label.md b/snippets/react/s/use-state-with-label.md similarity index 100% rename from snippets/articles/s/react-use-state-with-label.md rename to snippets/react/s/use-state-with-label.md