Travis build: 810 [ci skip]
This commit is contained in:
@ -3624,6 +3624,8 @@ truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex
|
||||
|
||||
### anagrams
|
||||
|
||||
⚠️ **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 anagrams of a string (contains duplicates).
|
||||
|
||||
Use recursion.
|
||||
|
||||
@ -743,7 +743,7 @@ size('size'); // 4
|
||||
size({ one: 1, two: 2, three: 3 }); // 3
|
||||
</code></pre></div></div><br/><div class="card fluid"><div class="section double-padded"><h3 id="truthcheckcollection">truthCheckCollection</h3></div><div class="section double-padded"><p>Checks if the predicate (second argument) is truthy on all elements of a collection (first argument).</p><p>Use <code>Array.every()</code> to check if each passed object has the specified property and if it returns a truthy value.</p><pre><code class="language-js">const truthCheckCollection = (collection, pre) => collection.every(obj => obj[pre]);
|
||||
</code></pre><pre><code class="language-js">truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex: 'male' }], 'sex'); // true
|
||||
</code></pre></div></div><br/><h2 style="text-align:center">String</h2><div class="card fluid"><div class="section double-padded"><h3 id="anagrams">anagrams</h3></div><div class="section double-padded"><p>Generates all anagrams of a string (contains duplicates).</p><p>Use recursion. For each letter in the given string, create all the partial anagrams for the rest of its letters. Use <code>Array.map()</code> to combine the letter with each partial anagram, then <code>Array.reduce()</code> to combine all anagrams in one array. Base cases are for string <code>length</code> equal to <code>2</code> or <code>1</code>.</p><pre><code class="language-js">const anagrams = str => {
|
||||
</code></pre></div></div><br/><h2 style="text-align:center">String</h2><div class="card fluid"><div class="section double-padded"><h3 id="anagrams">anagrams</h3></div><div class="section double-padded"><p>⚠️ <strong>WARNING</strong>: 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.</p><p>Generates all anagrams of a string (contains duplicates).</p><p>Use recursion. For each letter in the given string, create all the partial anagrams for the rest of its letters. Use <code>Array.map()</code> to combine the letter with each partial anagram, then <code>Array.reduce()</code> to combine all anagrams in one array. Base cases are for string <code>length</code> equal to <code>2</code> or <code>1</code>.</p><pre><code class="language-js">const anagrams = str => {
|
||||
if (str.length <= 2) return str.length === 2 ? [str, str[1] + str[0]] : [str];
|
||||
return str
|
||||
.split('')
|
||||
|
||||
Reference in New Issue
Block a user