From d995044ead0be7003111a0b9b8c3f6c93621941a Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 21 Nov 2019 22:01:52 +0200 Subject: [PATCH 1/4] Update permutations.md --- snippets/permutations.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/permutations.md b/snippets/permutations.md index 331c8af37..7252abecc 100644 --- a/snippets/permutations.md +++ b/snippets/permutations.md @@ -3,10 +3,10 @@ title: permutations tags: array,recursion,advanced --- -⚠️ **WARNING**: This function's execution time increases exponentially with each array element. Anything more than 8 to 10 entries will cause your browser to hang as it tries to solve all the different combinations. - Generates all permutations of an array's elements (contains duplicates). +⚠️ **WARNING**: This function's execution time increases exponentially with each array element. Anything more than 8 to 10 entries will cause your browser to hang as it tries to solve all the different combinations. + Use recursion. For each element in the given array, create all the partial permutations for the rest of its elements. Use `Array.prototype.map()` to combine the element with each partial permutation, then `Array.prototype.reduce()` to combine all permutations in one array. @@ -27,4 +27,4 @@ const permutations = arr => { ```js permutations([1, 33, 5]); // [ [ 1, 33, 5 ], [ 1, 5, 33 ], [ 33, 1, 5 ], [ 33, 5, 1 ], [ 5, 1, 33 ], [ 5, 33, 1 ] ] -``` \ No newline at end of file +``` From dace9222428912fdae4e80f7ba8e73930fc30ffc Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 21 Nov 2019 22:02:13 +0200 Subject: [PATCH 2/4] Update stringPermutations.md --- snippets/stringPermutations.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/stringPermutations.md b/snippets/stringPermutations.md index 6345b517a..30c477d71 100644 --- a/snippets/stringPermutations.md +++ b/snippets/stringPermutations.md @@ -3,10 +3,10 @@ title: stringPermutations tags: string,recursion,advanced --- -⚠️ **WARNING**: This function's execution time increases exponentially with each character. Anything more than 8 to 10 characters will cause your browser to hang as it tries to solve all the different combinations. - Generates all permutations of a string (contains duplicates). +⚠️ **WARNING**: This function's execution time increases exponentially with each character. Anything more than 8 to 10 characters will cause your browser to hang as it tries to solve all the different combinations. + Use recursion. For each letter in the given string, create all the partial permutations for the rest of its letters. Use `Array.prototype.map()` to combine the letter with each partial permutation, then `Array.prototype.reduce()` to combine all permutations in one array. @@ -27,4 +27,4 @@ const stringPermutations = str => { ```js stringPermutations('abc'); // ['abc','acb','bac','bca','cab','cba'] -``` \ No newline at end of file +``` From 700a5d8c128d21c856d25233ce753daee8a21c16 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 21 Nov 2019 22:02:28 +0200 Subject: [PATCH 3/4] Update hasKey.md --- snippets/hasKey.md | 1 - 1 file changed, 1 deletion(-) diff --git a/snippets/hasKey.md b/snippets/hasKey.md index 7513aa57c..d3020160d 100644 --- a/snippets/hasKey.md +++ b/snippets/hasKey.md @@ -8,7 +8,6 @@ Returns `true` if the target value exists in a JSON object, `false` otherwise. Check if `keys` is non-empty and use `Array.prototype.every()` to sequentially check its keys to internal depth of the object, `obj`. Use `Object.prototype.hasOwnProperty()` to check if `obj` does not have the current key or is not an object, stop propagation and return `false`. Otherwise assign the key's value to `obj` to use on the next iteration. - Return `false` beforehand if given key list is empty. ```js From 52ef8585b50a7cb6d2b01feff7726082ed01ac27 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 21 Nov 2019 22:02:44 +0200 Subject: [PATCH 4/4] Update copyToClipboard.md --- snippets/copyToClipboard.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/copyToClipboard.md b/snippets/copyToClipboard.md index d3d07d984..577e458ae 100644 --- a/snippets/copyToClipboard.md +++ b/snippets/copyToClipboard.md @@ -3,11 +3,11 @@ title: copyToClipboard tags: browser,string,advanced --- -⚠️ **NOTICE:** The same functionality can be easily implemented by using the new asynchronous Clipboard API, which is still experimental but should be used in the future instead of this snippet. Find out more about it [here](https://github.com/w3c/clipboard-apis/blob/master/explainer.adoc#writing-to-the-clipboard). - Copy a string to the clipboard. Only works as a result of user action (i.e. inside a `click` event listener). +⚠️ **NOTICE:** The same functionality can be easily implemented by using the new asynchronous Clipboard API, which is still experimental but should be used in the future instead of this snippet. Find out more about it [here](https://github.com/w3c/clipboard-apis/blob/master/explainer.adoc#writing-to-the-clipboard). + Create a new `