lodash-contrib
Version:
The brass buckles on lodash's utility belt
682 lines (488 loc) • 24.2 kB
HTML
<html>
<head>
<title>_.util.operators.js.md</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page_wrapper">
<div id="jump_page">
<a class="source" href="_.array.builders.js.html">
_.array.builders.js.md
</a>
<a class="source" href="_.array.selectors.js.html">
_.array.selectors.js.md
</a>
<a class="source" href="_.collections.walk.js.html">
_.collections.walk.js.md
</a>
<a class="source" href="_.function.arity.js.html">
_.function.arity.js.md
</a>
<a class="source" href="_.function.combinators.js.html">
_.function.combinators.js.md
</a>
<a class="source" href="_.function.iterators.js.html">
_.function.iterators.js.md
</a>
<a class="source" href="_.function.predicates.js.html">
_.function.predicates.js.md
</a>
<a class="source" href="_.object.builders.js.html">
_.object.builders.js.md
</a>
<a class="source" href="_.object.selectors.js.html">
_.object.selectors.js.md
</a>
<a class="source" href="_.util.existential.js.html">
_.util.existential.js.md
</a>
<a class="source" href="_.util.operators.js.html">
_.util.operators.js.md
</a>
<a class="source" href="_.util.strings.js.html">
_.util.strings.js.md
</a>
<a class="source" href="_.util.trampolines.js.html">
_.util.trampolines.js.md
</a>
<a class="source" href="index.html">
index.md
</a>
</div>
</div>
</li>
</ul>
<ul class="sections">
<li id="title">
<div class="annotation">
<h1>_.util.operators.js.md</h1>
</div>
</li>
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">¶</a>
</div>
<h3 id="util-operators">util.operators</h3>
<blockquote>
<p>Functions which wrap JavaScript’s operators.</p>
</blockquote>
<hr>
</div>
</li>
<li id="section-2">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<h4 id="add">add</h4>
<p><strong>Signature:</strong> <code>_.add(value:Number, value:Number[, value:Number...])</code></p>
<p>Returns the sum of the arguments.</p>
<pre><code class="lang-javascript">_.add(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>);
<span class="hljs-comment">// => 10</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-3">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-3">¶</a>
</div>
<h4 id="bitwiseand">bitwiseAnd</h4>
<p><strong>Signature:</strong> <code>_.bitwiseAnd(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code>&</code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseAnd(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => 1</span>
_.bitwiseAnd(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => 0</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-4">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-4">¶</a>
</div>
<h4 id="bitwiseleft">bitwiseLeft</h4>
<p><strong>Signature:</strong> <code>_.bitwiseLeft(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code><<</code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseLeft(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => 8</span>
_.bitwiseLeft(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => 32</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-5">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-5">¶</a>
</div>
<h4 id="bitwiseright">bitwiseRight</h4>
<p><strong>Signature:</strong> <code>_.bitwiseRight(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code>>></code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseRight(<span class="hljs-number">3</span>, <span class="hljs-number">1</span>);
<span class="hljs-comment">// => 1</span>
_.bitwiseRight(<span class="hljs-number">3</span>, <span class="hljs-number">1</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => 0</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-6">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-6">¶</a>
</div>
<h4 id="bitwisenot">bitwiseNot</h4>
<p><strong>Signature:</strong> <code>_.bitwiseNot(value:Any)</code></p>
<p>Returns the result of using the <code>~</code> operator on the value.</p>
<pre><code class="lang-javascript">_.bitwiseNot(<span class="hljs-number">1</span>);
<span class="hljs-comment">// => -2</span>
_.bitwiseOr(<span class="hljs-number">2</span>);
<span class="hljs-comment">// => -3</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-7">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-7">¶</a>
</div>
<h4 id="bitwiseor">bitwiseOr</h4>
<p><strong>Signature:</strong> <code>_.bitwiseOr(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code>|</code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseOr(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => 3</span>
_.bitwiseOr(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>);
<span class="hljs-comment">// => 7</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-8">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-8">¶</a>
</div>
<h4 id="bitwisexor">bitwiseXor</h4>
<p><strong>Signature:</strong> <code>_.bitwiseXor(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code>^</code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseXor(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => 2</span>
_.bitwiseXor(<span class="hljs-number">1</span>, <span class="hljs-number">3</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => 1</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-9">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-9">¶</a>
</div>
<h4 id="bitwisez">bitwiseZ</h4>
<p><strong>Signature:</strong> <code>_.bitwiseZ(value:Any, value:Any[, value:Any...])</code></p>
<p>Returns the result of using the <code>>>></code> operator on the arguments.</p>
<pre><code class="lang-javascript">_.bitwiseZ(<span class="hljs-number">72</span>, <span class="hljs-number">32</span>);
<span class="hljs-comment">// => 72</span>
_.bitwiseZ(<span class="hljs-number">72</span>, <span class="hljs-number">32</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => 18</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-10">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-10">¶</a>
</div>
<h4 id="dec">dec</h4>
<p><strong>Signature:</strong> <code>_.dec(value:Number)</code></p>
<p>Returns the result of decrementing the value by <code>1</code>.</p>
<pre><code class="lang-javascript">_.dec(<span class="hljs-number">2</span>);
<span class="hljs-comment">// => 1</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-11">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-11">¶</a>
</div>
<h4 id="div">div</h4>
<p><strong>Signature:</strong> <code>_.div(value:Number, value:Number[, value:Number...])</code></p>
<p>Returns the quotient of the arguments.</p>
<pre><code class="lang-javascript">_.div(<span class="hljs-number">8</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => 4</span>
_.div(<span class="hljs-number">8</span>, <span class="hljs-number">2</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => 2</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-12">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-12">¶</a>
</div>
<h4 id="eq">eq</h4>
<p><strong>Signature:</strong> <code>_.eq(value:Any, value:Any[, value:Any...])</code></p>
<p>Compares the arguments with loose equality (<code>==</code>).</p>
<pre><code class="lang-javascript">_.eq(<span class="hljs-number">1</span>, <span class="hljs-string">"1"</span>);
<span class="hljs-comment">// => true</span>
_.eq(<span class="hljs-number">1</span>, <span class="hljs-number">15</span>);
<span class="hljs-comment">// => false</span>
_.eq(<span class="hljs-number">1</span>, <span class="hljs-literal">true</span>, <span class="hljs-string">"1"</span>);
<span class="hljs-comment">// => true</span>
_.eq(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">15</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-13">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-13">¶</a>
</div>
<h4 id="gt">gt</h4>
<p><strong>Signature:</strong> <code>_.gt(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether each argument is greater than the previous argument.</p>
<pre><code class="lang-javascript">_.gt(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => true</span>
_.gt(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => true</span>
_.gt(<span class="hljs-number">1</span>, <span class="hljs-number">6</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-14">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-14">¶</a>
</div>
<h4 id="gte">gte</h4>
<p><strong>Signature:</strong> <code>_.gte(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether each argument is greater than or equal to the previous argument.</p>
<pre><code class="lang-javascript">_.gte(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => true</span>
_.gte(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => true</span>
_.gte(<span class="hljs-number">1</span>, <span class="hljs-number">6</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-15">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-15">¶</a>
</div>
<h4 id="inc">inc</h4>
<p><strong>Signature:</strong> <code>_.inc(value:Number)</code></p>
<p>Returns the result of incrementing the value by <code>1</code>.</p>
<pre><code class="lang-javascript">_.inc(<span class="hljs-number">2</span>);
<span class="hljs-comment">// => 3</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-16">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-16">¶</a>
</div>
<h4 id="lt">lt</h4>
<p><strong>Signature:</strong> <code>_.lt(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether each argument is less than the previous argument.</p>
<pre><code class="lang-javascript">_.lt(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>);
<span class="hljs-comment">// => true</span>
_.lt(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>);
<span class="hljs-comment">// => true</span>
_.lt(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">12</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-17">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-17">¶</a>
</div>
<h4 id="lte">lte</h4>
<p><strong>Signature:</strong> <code>_.lte(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether each argument is less than or equal to the previous argument.</p>
<pre><code class="lang-javascript">_.lte(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>);
<span class="hljs-comment">// => true</span>
_.lte(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>);
<span class="hljs-comment">// => true</span>
_.lte(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">12</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-18">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-18">¶</a>
</div>
<h4 id="mul">mul</h4>
<p><strong>Signature:</strong> <code>_.mul(value:Number, value:Number[, value:Number...])</code></p>
<p>Returns the product of the arguments.</p>
<pre><code class="lang-javascript">_.mul(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>);
<span class="hljs-comment">// => 24</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-19">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-19">¶</a>
</div>
<h4 id="mod">mod</h4>
<p><strong>Signature:</strong> <code>_.mod(dividend:Number, divisor:Number)</code></p>
<p>Returns the remainder of dividing <code>dividend</code> by <code>divisor</code>.</p>
<pre><code class="lang-javascript">_.mod(<span class="hljs-number">26</span>, <span class="hljs-number">5</span>);
<span class="hljs-comment">// => 1</span>
_.mod(<span class="hljs-number">14</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => 2</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-20">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-20">¶</a>
</div>
<h4 id="neg">neg</h4>
<p><strong>Signature:</strong> <code>_.neg(num:Number)</code></p>
<p>Returns a new number with the opposite sign value of <code>num</code>.</p>
<pre><code class="lang-javascript">_.neg(<span class="hljs-number">5</span>);
<span class="hljs-comment">// => -5</span>
_.neg(-<span class="hljs-number">3</span>);
<span class="hljs-comment">// => 3</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-21">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-21">¶</a>
</div>
<h4 id="neq">neq</h4>
<p><strong>Signature:</strong> <code>_.neq(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether each argument is not equal to the previous argument, using loose
inequality (<code>!=</code>).</p>
<pre><code class="lang-javascript">_.neq(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>);
<span class="hljs-comment">// => true</span>
_.neq(<span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>);
<span class="hljs-comment">// => true</span>
_.neq(<span class="hljs-number">1</span>, <span class="hljs-number">1</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-22">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-22">¶</a>
</div>
<h4 id="not">not</h4>
<p><strong>Signature:</strong> <code>_.not(value:Any)</code></p>
<p>Returns a boolean which is the opposite of the truthiness of the original value.</p>
<pre><code class="lang-javascript">_.not(<span class="hljs-number">0</span>);
<span class="hljs-comment">// => true</span>
_.not(<span class="hljs-number">1</span>);
<span class="hljs-comment">// => false</span>
_.not(<span class="hljs-literal">true</span>);
<span class="hljs-comment">// => false</span>
_.not(<span class="hljs-literal">false</span>);
<span class="hljs-comment">// => true</span>
_.not({});
<span class="hljs-comment">// => false</span>
_.not(<span class="hljs-literal">null</span>);
<span class="hljs-comment">// => true</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-23">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-23">¶</a>
</div>
<h4 id="seq">seq</h4>
<p><strong>Signature:</strong> <code>_.seq(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether the arguments are strictly equal (<code>===</code>) to each other.</p>
<pre><code class="lang-javascript">_.seq(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => true</span>
_.seq(<span class="hljs-number">2</span>, <span class="hljs-string">"2"</span>);
<span class="hljs-comment">// => false</span>
_.seq(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => true</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-24">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-24">¶</a>
</div>
<h4 id="sneq">sneq</h4>
<p><strong>Signature:</strong> <code>_.sneq(value:Any, value:Any[, value:Any...])</code></p>
<p>Checks whether the arguments are strictly not equal (<code>!==</code>) to each other.</p>
<pre><code class="lang-javascript">_.sneq(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => false</span>
_.sneq(<span class="hljs-number">2</span>, <span class="hljs-string">"2"</span>);
<span class="hljs-comment">// => true</span>
_.sneq(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>, <span class="hljs-number">2</span>);
<span class="hljs-comment">// => false</span>
</code></pre>
<hr>
</div>
</li>
<li id="section-25">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-25">¶</a>
</div>
<h4 id="sub">sub</h4>
<p><strong>Signature:</strong> <code>_.sub(value:Number, value:Number[, value:Number...])</code></p>
<p>Returns the difference of the arguments.</p>
<pre><code class="lang-javascript">_.sub(<span class="hljs-number">10</span>, <span class="hljs-number">3</span>);
<span class="hljs-comment">// => 7</span>
_.sub(<span class="hljs-number">10</span>, <span class="hljs-number">3</span>, <span class="hljs-number">5</span>);
<span class="hljs-comment">// => 2</span>
</code></pre>
</div>
</li>
</ul>
</div>
</body>
</html>