Travis build: 1996

This commit is contained in:
30secondsofcode
2018-04-26 17:45:21 +00:00
parent 79a149c9df
commit 7a9c94f37c
2 changed files with 4 additions and 16 deletions

View File

@ -7259,18 +7259,12 @@ pad('foobar', 3); // 'foobar'
Returns `true` if the given string is a palindrome, `false` otherwise.
Convert string `String.toLowerCase()` and use `String.replace()` to remove non-alphanumeric characters from it.
Then, `String.split('')` into individual characters, `Array.reverse()`, `String.join('')` and compare to the original, unreversed string, after converting it `String.tolowerCase()`.
Then, use the spread operator (`...`) to split string into individual characters, `Array.reverse()`, `String.join('')` and compare to the original, unreversed string, after converting it `String.tolowerCase()`.
```js
const palindrome = str => {
const s = str.toLowerCase().replace(/[\W_]/g, '');
return (
s ===
s
.split('')
.reverse()
.join('')
);
return s === [...s].reverse().join('');
};
```

View File

@ -148,15 +148,9 @@
</pre><label class="collapse">Show examples</label><pre class="language-js"><span class="token function">pad</span><span class="token punctuation">(</span><span class="token string">'cat'</span><span class="token punctuation">,</span> <span class="token number">8</span><span class="token punctuation">);</span> <span class="token comment">// ' cat '</span>
<span class="token function">pad</span><span class="token punctuation">(</span><span class="token function">String</span><span class="token punctuation">(</span><span class="token number">42</span><span class="token punctuation">),</span> <span class="token number">6</span><span class="token punctuation">,</span> <span class="token string">'0'</span><span class="token punctuation">);</span> <span class="token comment">// '004200'</span>
<span class="token function">pad</span><span class="token punctuation">(</span><span class="token string">'foobar'</span><span class="token punctuation">,</span> <span class="token number">3</span><span class="token punctuation">);</span> <span class="token comment">// 'foobar'</span>
</pre><button class="primary clipboard-copy">&#128203;&nbsp;Copy to clipboard</button></div></div><div class="card fluid"><h3 id="palindrome" class="section double-padded">palindrome</h3><div class="section double-padded"><p>Returns <code>true</code> if the given string is a palindrome, <code>false</code> otherwise.</p><p>Convert string <code>String.toLowerCase()</code> and use <code>String.replace()</code> to remove non-alphanumeric characters from it. Then, <code>String.split('')</code> into individual characters, <code>Array.reverse()</code>, <code>String.join('')</code> and compare to the original, unreversed string, after converting it <code>String.tolowerCase()</code>.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">palindrome</span> <span class="token operator">=</span> str <span class="token operator">=></span> <span class="token punctuation">{</span>
</pre><button class="primary clipboard-copy">&#128203;&nbsp;Copy to clipboard</button></div></div><div class="card fluid"><h3 id="palindrome" class="section double-padded">palindrome</h3><div class="section double-padded"><p>Returns <code>true</code> if the given string is a palindrome, <code>false</code> otherwise.</p><p>Convert string <code>String.toLowerCase()</code> and use <code>String.replace()</code> to remove non-alphanumeric characters from it. Then, use the spread operator (<code>...</code>) to split string into individual characters, <code>Array.reverse()</code>, <code>String.join('')</code> and compare to the original, unreversed string, after converting it <code>String.tolowerCase()</code>.</p><pre class="language-js"><span class="token keyword">const</span> <span class="token function-variable function">palindrome</span> <span class="token operator">=</span> str <span class="token operator">=></span> <span class="token punctuation">{</span>
<span class="token keyword">const</span> s <span class="token operator">=</span> str<span class="token punctuation">.</span><span class="token function">toLowerCase</span><span class="token punctuation">().</span><span class="token function">replace</span><span class="token punctuation">(</span><span class="token regex">/[\W_]/g</span><span class="token punctuation">,</span> <span class="token string">''</span><span class="token punctuation">);</span>
<span class="token keyword">return</span> <span class="token punctuation">(</span>
s <span class="token operator">===</span>
s
<span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)
.</span><span class="token function">reverse</span><span class="token punctuation">()
.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">)
);
<span class="token keyword">return</span> s <span class="token operator">===</span> <span class="token punctuation">[</span><span class="token operator">...</span>s<span class="token punctuation">].</span><span class="token function">reverse</span><span class="token punctuation">().</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">''</span><span class="token punctuation">);
};</span>
</pre><label class="collapse">Show examples</label><pre class="language-js"><span class="token function">palindrome</span><span class="token punctuation">(</span><span class="token string">'taco cat'</span><span class="token punctuation">);</span> <span class="token comment">// true</span>
</pre><button class="primary clipboard-copy">&#128203;&nbsp;Copy to clipboard</button></div></div><div class="card fluid"><h3 id="pluralize" class="section double-padded">pluralize</h3><div class="section double-padded"><p>Returns the singular or plural form of the word based on the input number. If the first argument is an <code>object</code>, it will use a closure by returning a function that can auto-pluralize words that don't simply end in <code>s</code> if the supplied dictionary contains the word.</p><p>If <code>num</code> is either <code>-1</code> or <code>1</code>, return the singular form of the word. If <code>num</code> is any other number, return the plural form. Omit the third argument to use the default of the singular word + <code>s</code>, or supply a custom pluralized word when necessary. If the first argument is an <code>object</code>, utilize a closure by returning a function which can use the supplied dictionary to resolve the correct plural form of the word.</p><pre class="language-js"><span class="token keyword">const</span> pluralize <span class="token operator">=</span> <span class="token punctuation">(</span>val<span class="token punctuation">,</span> word<span class="token punctuation">,</span> plural <span class="token operator">=</span> word <span class="token operator">+</span> <span class="token string">'s'</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span>