Travis build: 987
This commit is contained in:
@ -295,7 +295,7 @@ Foo<span class="token punctuation">.</span>prototype<span class="token punctuati
|
||||
Object<span class="token punctuation">.</span><span class="token function">keys</span><span class="token punctuation">(</span>source<span class="token punctuation">).</span><span class="token function">every</span><span class="token punctuation">(</span>key <span class="token operator">=></span> obj<span class="token punctuation">.</span><span class="token function">hasOwnProperty</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span> <span class="token operator">&&</span> obj<span class="token punctuation">[</span>key<span class="token punctuation">]</span> <span class="token operator">===</span> source<span class="token punctuation">[</span>key<span class="token punctuation">]);</span>
|
||||
</pre><label class="collapse">examples</label><pre class="section card-examples language-js"><span class="token function">matches</span><span class="token punctuation">({</span> age<span class="token punctuation">:</span> <span class="token number">25</span><span class="token punctuation">,</span> hair<span class="token punctuation">:</span> <span class="token string">'long'</span><span class="token punctuation">,</span> beard<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">}, {</span> hair<span class="token punctuation">:</span> <span class="token string">'long'</span><span class="token punctuation">,</span> beard<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">});</span> <span class="token comment">// true</span>
|
||||
<span class="token function">matches</span><span class="token punctuation">({</span> hair<span class="token punctuation">:</span> <span class="token string">'long'</span><span class="token punctuation">,</span> beard<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">}, {</span> age<span class="token punctuation">:</span> <span class="token number">25</span><span class="token punctuation">,</span> hair<span class="token punctuation">:</span> <span class="token string">'long'</span><span class="token punctuation">,</span> beard<span class="token punctuation">:</span> <span class="token boolean">true</span> <span class="token punctuation">});</span> <span class="token comment">// false</span>
|
||||
</pre></div><div class="card code-card"><div class="corner intermediate"></div><div class="section card-content"><h4 id="matcheswith">matchesWith</h4><p>Compares two objects to determine if the first one contains equivalent property values to the second one, based on a provided function.</p><p>Use <code>Object.keys(source)</code> to get all the keys of the second object, then <code>Array.prototype.every()</code>, <code>Object.hasOwnProperty()</code> and the provided function to determine if all keys exist in the first object and have equivalent values. If no function is provided, the values will be compared using the equality operator.</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">matchesWith</span> <span class="token operator">=</span> <span class="token punctuation">(</span>obj<span class="token punctuation">,</span> source<span class="token punctuation">,</span> fn<span class="token punctuation">)</span> <span class="token operator">=></span>
|
||||
</pre></div><div class="card code-card"><div class="section card-content"><h4><a href="https://frontendmasters.com/courses/es6-right-parts/" target="_blank" rel="noopener noreferrer">Recommended Resource - ES6: The Right Parts</a></h4><p>Learn new ES6 JavaScript language features like arrow function, destructuring, generators & more to write cleaner and more productive, readable programs.</p></div></div><div class="card code-card"><div class="corner intermediate"></div><div class="section card-content"><h4 id="matcheswith">matchesWith</h4><p>Compares two objects to determine if the first one contains equivalent property values to the second one, based on a provided function.</p><p>Use <code>Object.keys(source)</code> to get all the keys of the second object, then <code>Array.prototype.every()</code>, <code>Object.hasOwnProperty()</code> and the provided function to determine if all keys exist in the first object and have equivalent values. If no function is provided, the values will be compared using the equality operator.</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">matchesWith</span> <span class="token operator">=</span> <span class="token punctuation">(</span>obj<span class="token punctuation">,</span> source<span class="token punctuation">,</span> fn<span class="token punctuation">)</span> <span class="token operator">=></span>
|
||||
Object<span class="token punctuation">.</span><span class="token function">keys</span><span class="token punctuation">(</span>source<span class="token punctuation">).</span><span class="token function">every</span><span class="token punctuation">(</span>
|
||||
key <span class="token operator">=></span>
|
||||
obj<span class="token punctuation">.</span><span class="token function">hasOwnProperty</span><span class="token punctuation">(</span>key<span class="token punctuation">)</span> <span class="token operator">&&</span> fn
|
||||
|
||||
Reference in New Issue
Block a user