Travis build: 552

This commit is contained in:
30secondsofcode
2018-09-28 19:47:25 +00:00
parent 8a5422a1a3
commit 7e2605ad84
13 changed files with 461 additions and 461 deletions

View File

@ -75,7 +75,7 @@
}, 1700);
}
}, false);
}</script></head><body onload="loader()" class="card-page"><a href="https://github.com/30-seconds/30-seconds-of-code" class="github-corner" aria-label="View source on Github"><svg width="56" height="56" viewBox="0 0 250 250" style="fill:#009688;color:#fff;position:fixed;top:0;border:0;right:0;z-index:1000" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin:130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><header><h1 class="logo"><a href="./index"><img src="https://30secondsofcode.org/logos/logo_256.png" alt="logo"/><span id="title">&nbsp;30 seconds of code</span> <small>Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.</small></a></h1></header><div class="container card-container"><main class="col-centered"><span id="top"><br><br></span><h2 class="category-name">Snippets Archive</h2><p style="text-align:justify">These snippets, while useful and interesting, didn't quite make it into the repository due to either having very specific use-cases or being outdated. However we felt like they might still be useful to some readers, so here they are.</p><br/><div class="card code-card"><div class="section card-content"><h4 id="binarysearch.md">binarySearch</h4><p>Use recursion. Similar to <code>Array.indexOf()</code> that finds the index of a value within an array. The difference being this operation only works with sorted arrays which offers a major performance boost due to it's logarithmic nature when compared to a linear search or <code>Array.indexOf()</code>.</p><p>Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search is less than the item in the middle of the interval, recurse into the lower half. Otherwise recurse into the upper half. Repeatedly recurse until the value is found which is the mid or you've recursed to a point that is greater than the length which means the value doesn't exist and return <code>-1</code>.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">binarySearch</span> <span class="token operator">=</span> <span class="token punctuation">(</span>arr<span class="token punctuation">,</span> val<span class="token punctuation">,</span> start <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">,</span> end <span class="token operator">=</span> arr<span class="token punctuation">.</span>length <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
}</script></head><body onload="loader()" class="card-page"><a href="https://github.com/30-seconds/30-seconds-of-code" class="github-corner" aria-label="View source on Github"><svg width="56" height="56" viewBox="0 0 250 250" style="fill:#009688;color:#fff;position:fixed;top:0;border:0;right:0;z-index:1000" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin:130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><header><h1 class="logo"><a href="./index"><img src="https://30secondsofcode.org/logos/logo_256.png" alt="logo"/><span id="title">&nbsp;30 seconds of code</span> <small>Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.</small></a></h1></header><div class="container card-container"><main class="col-centered"><span id="top"><br><br></span><h2 class="category-name">Snippets Archive</h2><p style="text-align:justify">These snippets, while useful and interesting, didn't quite make it into the repository due to either having very specific use-cases or being outdated. However we felt like they might still be useful to some readers, so here they are.</p><br/><div class="card code-card"><div class="section card-content"><h4 id="binarysearch.md">binarySearch</h4><p>Use recursion. Similar to <code>Array.prototype.indexOf()</code> that finds the index of a value within an array. The difference being this operation only works with sorted arrays which offers a major performance boost due to it's logarithmic nature when compared to a linear search or <code>Array.prototype.indexOf()</code>.</p><p>Search a sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search is less than the item in the middle of the interval, recurse into the lower half. Otherwise recurse into the upper half. Repeatedly recurse until the value is found which is the mid or you've recursed to a point that is greater than the length which means the value doesn't exist and return <code>-1</code>.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">binarySearch</span> <span class="token operator">=</span> <span class="token punctuation">(</span>arr<span class="token punctuation">,</span> val<span class="token punctuation">,</span> start <span class="token operator">=</span> <span class="token number">0</span><span class="token punctuation">,</span> end <span class="token operator">=</span> arr<span class="token punctuation">.</span>length <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>start <span class="token operator">></span> end<span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> mid <span class="token operator">=</span> Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">((</span>start <span class="token operator">+</span> end<span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">);</span>
<span class="token keyword">if</span> <span class="token punctuation">(</span>arr<span class="token punctuation">[</span>mid<span class="token punctuation">]</span> <span class="token operator">></span> val<span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token function">binarySearch</span><span class="token punctuation">(</span>arr<span class="token punctuation">,</span> val<span class="token punctuation">,</span> start<span class="token punctuation">,</span> mid <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">);</span>
@ -101,7 +101,7 @@
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="countvowels.md">countVowels</h4><p>Retuns <code>number</code> of vowels in provided string.</p><p>Use a regular expression to count the number of vowels <code>(A, E, I, O, U)</code> in a <code>string</code>.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">countVowels</span> <span class="token operator">=</span> str <span class="token operator">=></span> <span class="token punctuation">(</span>str<span class="token punctuation">.</span><span class="token function">match</span><span class="token punctuation">(</span><span class="token regex">/[aeiou]/gi</span><span class="token punctuation">)</span> <span class="token operator">||</span> <span class="token punctuation">[]).</span>length<span class="token punctuation">;</span>
</pre><label class="collapse">examples</label><pre class="section card-examples language-js"><span class="token function">countVowels</span><span class="token punctuation">(</span><span class="token string">'foobar'</span><span class="token punctuation">);</span> <span class="token comment">// 3</span>
<span class="token function">countVowels</span><span class="token punctuation">(</span><span class="token string">'gym'</span><span class="token punctuation">);</span> <span class="token comment">// 0</span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="factors.md">factors</h4><p>Returns the array of factors of the given <code>num</code>. If the second argument is set to <code>true</code> returns only the prime factors of <code>num</code>. If <code>num</code> is <code>1</code> or <code>0</code> returns an empty array. If <code>num</code> is less than <code>0</code> returns all the factors of <code>-int</code> together with their additive inverses.</p><p>Use <code>Array.from()</code>, <code>Array.map()</code> and <code>Array.filter()</code> to find all the factors of <code>num</code>. If given <code>num</code> is negative, use <code>Array.reduce()</code> to add the additive inverses to the array. Return all results if <code>primes</code> is <code>false</code>, else determine and return only the prime factors using <code>isPrime</code> and <code>Array.filter()</code>. Omit the second argument, <code>primes</code>, to return prime and non-prime factors by default.</p><p><strong>Note</strong>:- <em>Negative numbers are not considered prime.</em></p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">factors</span> <span class="token operator">=</span> <span class="token punctuation">(</span>num<span class="token punctuation">,</span> primes <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="factors.md">factors</h4><p>Returns the array of factors of the given <code>num</code>. If the second argument is set to <code>true</code> returns only the prime factors of <code>num</code>. If <code>num</code> is <code>1</code> or <code>0</code> returns an empty array. If <code>num</code> is less than <code>0</code> returns all the factors of <code>-int</code> together with their additive inverses.</p><p>Use <code>Array.from()</code>, <code>Array.prototype.map()</code> and <code>Array.prototype.filter()</code> to find all the factors of <code>num</code>. If given <code>num</code> is negative, use <code>Array.prototype.reduce()</code> to add the additive inverses to the array. Return all results if <code>primes</code> is <code>false</code>, else determine and return only the prime factors using <code>isPrime</code> and <code>Array.prototype.filter()</code>. Omit the second argument, <code>primes</code>, to return prime and non-prime factors by default.</p><p><strong>Note</strong>:- <em>Negative numbers are not considered prime.</em></p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">factors</span> <span class="token operator">=</span> <span class="token punctuation">(</span>num<span class="token punctuation">,</span> primes <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>
<span class="token keyword">const</span> <span class="token function-variable function">isPrime</span> <span class="token operator">=</span> num <span class="token operator">=></span> <span class="token punctuation">{</span>
<span class="token keyword">const</span> boundary <span class="token operator">=</span> Math<span class="token punctuation">.</span><span class="token function">floor</span><span class="token punctuation">(</span>Math<span class="token punctuation">.</span><span class="token function">sqrt</span><span class="token punctuation">(</span>num<span class="token punctuation">));</span>
<span class="token keyword">for</span> <span class="token punctuation">(</span><span class="token keyword">var</span> i <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span> i <span class="token operator">&lt;=</span> boundary<span class="token punctuation">;</span> i<span class="token operator">++</span><span class="token punctuation">)</span> <span class="token keyword">if</span> <span class="token punctuation">(</span>num <span class="token operator">%</span> i <span class="token operator">===</span> <span class="token number">0</span><span class="token punctuation">)</span> <span class="token keyword">return</span> <span class="token boolean">false</span><span class="token punctuation">;</span>
@ -127,7 +127,7 @@
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="fibonaccicountuntilnum.md">fibonacciCountUntilNum</h4><p>Returns the number of fibonnacci numbers up to <code>num</code>(<code>0</code> and <code>num</code> inclusive).</p><p>Use a mathematical formula to calculate the number of fibonacci numbers until <code>num</code>.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">fibonacciCountUntilNum</span> <span class="token operator">=</span> num <span class="token operator">=></span>
Math<span class="token punctuation">.</span><span class="token function">ceil</span><span class="token punctuation">(</span>Math<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>num <span class="token operator">*</span> Math<span class="token punctuation">.</span><span class="token function">sqrt</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token operator">/</span> Math<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">((</span>Math<span class="token punctuation">.</span><span class="token function">sqrt</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">));</span>
</pre><label class="collapse">examples</label><pre class="section card-examples language-js"><span class="token function">fibonacciCountUntilNum</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">);</span> <span class="token comment">// 7</span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="fibonacciuntilnum.md">fibonacciUntilNum</h4><p>Generates an array, containing the Fibonacci sequence, up until the nth term.</p><p>Create an empty array of the specific length, initializing the first two values (<code>0</code> and <code>1</code>). Use <code>Array.reduce()</code> to add values into the array, using the sum of the last two values, except for the first two. Uses a mathematical formula to calculate the length of the array required.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">fibonacciUntilNum</span> <span class="token operator">=</span> num <span class="token operator">=></span> <span class="token punctuation">{</span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="fibonacciuntilnum.md">fibonacciUntilNum</h4><p>Generates an array, containing the Fibonacci sequence, up until the nth term.</p><p>Create an empty array of the specific length, initializing the first two values (<code>0</code> and <code>1</code>). Use <code>Array.prototype.reduce()</code> to add values into the array, using the sum of the last two values, except for the first two. Uses a mathematical formula to calculate the length of the array required.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">fibonacciUntilNum</span> <span class="token operator">=</span> num <span class="token operator">=></span> <span class="token punctuation">{</span>
<span class="token keyword">let</span> n <span class="token operator">=</span> Math<span class="token punctuation">.</span><span class="token function">ceil</span><span class="token punctuation">(</span>Math<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>num <span class="token operator">*</span> Math<span class="token punctuation">.</span><span class="token function">sqrt</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token operator">/</span> Math<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">((</span>Math<span class="token punctuation">.</span><span class="token function">sqrt</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">+</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token operator">/</span> <span class="token number">2</span><span class="token punctuation">));</span>
<span class="token keyword">return</span> Array<span class="token punctuation">.</span><span class="token keyword">from</span><span class="token punctuation">({</span> length<span class="token punctuation">:</span> n <span class="token punctuation">}).</span><span class="token function">reduce</span><span class="token punctuation">(
(</span>acc<span class="token punctuation">,</span> val<span class="token punctuation">,</span> i<span class="token punctuation">)</span> <span class="token operator">=></span> acc<span class="token punctuation">.</span><span class="token function">concat</span><span class="token punctuation">(</span>i <span class="token operator">></span> <span class="token number">1</span> <span class="token operator">?</span> acc<span class="token punctuation">[</span>i <span class="token operator">-</span> <span class="token number">1</span><span class="token punctuation">]</span> <span class="token operator">+</span> acc<span class="token punctuation">[</span>i <span class="token operator">-</span> <span class="token number">2</span><span class="token punctuation">] :</span> i<span class="token punctuation">),
@ -224,7 +224,7 @@
<span class="token function">compareStrings</span><span class="token punctuation">(</span><span class="token string">'30-seconds-of-code'</span><span class="token punctuation">,</span> <span class="token string">'30-seconds-of-python-code'</span><span class="token punctuation">);</span> <span class="token comment">// 99.72 (%)</span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="pipelog.md">pipeLog</h4><p>Logs a value and returns it.</p><p>Use <code>console.log</code> to log the supplied value, combined with the <code>||</code> operator to return it.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">pipeLog</span> <span class="token operator">=</span> data <span class="token operator">=></span> console<span class="token punctuation">.</span><span class="token function">log</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span> <span class="token operator">||</span> data<span class="token punctuation">;</span>
</pre><label class="collapse">examples</label><pre class="section card-examples language-js"><span class="token function">pipeLog</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">);</span> <span class="token comment">// logs `1` and returns `1`</span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="quicksort.md">quickSort</h4><p>QuickSort an Array (ascending sort by default).</p><p>Use recursion. Use <code>Array.filter</code> and spread operator (<code>...</code>) to create an array that all elements with values less than the pivot come before the pivot, and all elements with values greater than the pivot come after it. If the parameter <code>desc</code> is truthy, return array sorts in descending order.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">quickSort</span> <span class="token operator">=</span> <span class="token punctuation">([</span>n<span class="token punctuation">,</span> <span class="token operator">...</span>nums<span class="token punctuation">],</span> desc<span class="token punctuation">)</span> <span class="token operator">=></span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="quicksort.md">quickSort</h4><p>QuickSort an Array (ascending sort by default).</p><p>Use recursion. Use <code>Array.prototype.filter</code> and spread operator (<code>...</code>) to create an array that all elements with values less than the pivot come before the pivot, and all elements with values greater than the pivot come after it. If the parameter <code>desc</code> is truthy, return array sorts in descending order.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">quickSort</span> <span class="token operator">=</span> <span class="token punctuation">([</span>n<span class="token punctuation">,</span> <span class="token operator">...</span>nums<span class="token punctuation">],</span> desc<span class="token punctuation">)</span> <span class="token operator">=></span>
<span class="token function">isNaN</span><span class="token punctuation">(</span>n<span class="token punctuation">)</span>
<span class="token operator">?</span> <span class="token punctuation">[]
: [</span>
@ -234,10 +234,10 @@
];</span>
</pre><label class="collapse">examples</label><pre class="section card-examples language-js"><span class="token function">quickSort</span><span class="token punctuation">([</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">]);</span> <span class="token comment">// [1,2,3,4]</span>
<span class="token function">quickSort</span><span class="token punctuation">([</span><span class="token number">4</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">],</span> <span class="token boolean">true</span><span class="token punctuation">);</span> <span class="token comment">// [4,3,2,1]</span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="removevowels.md">removeVowels</h4><p>Returns all the vowels in a <code>str</code> replaced by <code>repl</code>.</p><p>Use <code>String.replace()</code> with a regexp to replace all vowels in <code>str</code>. Omot <code>repl</code> to use a default value of <code>''</code>.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> removeVowels <span class="token operator">=</span> <span class="token punctuation">(</span>str<span class="token punctuation">,</span> repl <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">)</span> <span class="token operator">=></span> str<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex">/[aeiou]/gi</span><span class="token punctuation">,</span> repl<span class="token punctuation">);</span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="removevowels.md">removeVowels</h4><p>Returns all the vowels in a <code>str</code> replaced by <code>repl</code>.</p><p>Use <code>String.prototype.replace()</code> with a regexp to replace all vowels in <code>str</code>. Omot <code>repl</code> to use a default value of <code>''</code>.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> removeVowels <span class="token operator">=</span> <span class="token punctuation">(</span>str<span class="token punctuation">,</span> repl <span class="token operator">=</span> <span class="token string">''</span><span class="token punctuation">)</span> <span class="token operator">=></span> str<span class="token punctuation">.</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex">/[aeiou]/gi</span><span class="token punctuation">,</span> repl<span class="token punctuation">);</span>
</pre><label class="collapse">examples</label><pre class="section card-examples language-js"><span class="token function">removeVowels</span><span class="token punctuation">(</span><span class="token string">"foobAr"</span><span class="token punctuation">);</span> <span class="token comment">// "fbr"</span>
<span class="token function">removeVowels</span><span class="token punctuation">(</span><span class="token string">"foobAr"</span><span class="token punctuation">,</span><span class="token string">"*"</span><span class="token punctuation">);</span> <span class="token comment">// "f**b*r"</span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="solverpn.md">solveRPN</h4><p>Solves the given mathematical expression in <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation">reverse polish notation</a>. Throws appropriate errors if there are unrecognized symbols or the expression is wrong. The valid operators are :- <code>+</code>,<code>-</code>,<code>*</code>,<code>/</code>,<code>^</code>,<code>**</code> (<code>^</code>&amp;<code>**</code> are the exponential symbols and are same). This snippet does not supports any unary operators.</p><p>Use a dictionary, <code>OPERATORS</code> to specify each operator's matching mathematical operation. Use <code>String.replace()</code> with a regular expression to replace <code>^</code> with <code>**</code>, <code>String.split()</code> to tokenize the string and <code>Array.filter()</code> to remove empty tokens. Use <code>Array.forEach()</code> to parse each <code>symbol</code>, evaluate it as a numeric value or operator and solve the mathematical expression. Numeric values are converted to floating point numbers and pushed to a <code>stack</code>, while operators are evaluated using the <code>OPERATORS</code> dictionary and pop elements from the <code>stack</code> to apply operations.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">solveRPN</span> <span class="token operator">=</span> rpn <span class="token operator">=></span> <span class="token punctuation">{</span>
</pre></div><div class="card code-card"><div class="section card-content"><h4 id="solverpn.md">solveRPN</h4><p>Solves the given mathematical expression in <a href="https://en.wikipedia.org/wiki/Reverse_Polish_notation">reverse polish notation</a>. Throws appropriate errors if there are unrecognized symbols or the expression is wrong. The valid operators are :- <code>+</code>,<code>-</code>,<code>*</code>,<code>/</code>,<code>^</code>,<code>**</code> (<code>^</code>&amp;<code>**</code> are the exponential symbols and are same). This snippet does not supports any unary operators.</p><p>Use a dictionary, <code>OPERATORS</code> to specify each operator's matching mathematical operation. Use <code>String.prototype.replace()</code> with a regular expression to replace <code>^</code> with <code>**</code>, <code>String.prototype.split()</code> to tokenize the string and <code>Array.prototype.filter()</code> to remove empty tokens. Use <code>Array.prototype.forEach()</code> to parse each <code>symbol</code>, evaluate it as a numeric value or operator and solve the mathematical expression. Numeric values are converted to floating point numbers and pushed to a <code>stack</code>, while operators are evaluated using the <code>OPERATORS</code> dictionary and pop elements from the <code>stack</code> to apply operations.</p></div><div class="copy-button-container"><button class="copy-button" aria-label="Copy to clipboard"></button></div><pre class="section card-code language-js"><span class="token keyword">const</span> <span class="token function-variable function">solveRPN</span> <span class="token operator">=</span> rpn <span class="token operator">=></span> <span class="token punctuation">{</span>
<span class="token keyword">const</span> <span class="token constant">OPERATORS</span> <span class="token operator">=</span> <span class="token punctuation">{</span>
<span class="token string">'*'</span><span class="token punctuation">: (</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span> <span class="token operator">=></span> a <span class="token operator">*</span> b<span class="token punctuation">,</span>
<span class="token string">'+'</span><span class="token punctuation">: (</span>a<span class="token punctuation">,</span> b<span class="token punctuation">)</span> <span class="token operator">=></span> a <span class="token operator">+</span> b<span class="token punctuation">,</span>