Skip to content

Commit

Permalink
feat: Added difference function
Browse files Browse the repository at this point in the history
  • Loading branch information
terkelg committed Oct 29, 2016
1 parent 482a329 commit 60f3e9f
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ https://unpkg.com/math-toolbox/dist/math-toolbox.umd.min.js
| percent | Calculate percantage of value. |
| isOdd | Returns true if the number given is odd. |
| isEven | Returns true if the number given is even. |
| difference | Returns the absolute difference between two values. |

## Plans
See GitHub Wiki:
Expand Down
83 changes: 83 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@ <h3 class='mb0 no-anchor'></h3>

</li>


<li><a
href='#difference'
class="">
difference

</a>

</li>

</ul>
</div>
<div class='mt1 h6 quiet'>
Expand Down Expand Up @@ -2288,6 +2298,79 @@ <h3 class='fl m0' id='percent'>



</section>




<section class='p2 mb2 clearfix bg-white minishadow'>


<div class='clearfix'>
<h3 class='fl m0' id='difference'>
difference
</h3>

</div>


<p>The absolute difference between two values.</p>


<div class='pre p1 fill-light mt0'>difference(a: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, b: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>): <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></div>










<div class='py1 quiet mt1 prose-big'>Parameters</div>
<div class='prose'>

<div class='space-bottom0'>
<div>
<span class='code bold'>a</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</code> The first value to check.

</div>

</div>

<div class='space-bottom0'>
<div>
<span class='code bold'>b</span> <code class='quiet'>(<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</code> The second value to check.

</div>

</div>

</div>






<div class='py1 quiet mt1 prose-big'>Returns</div>
<code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>:
The absolute difference between the two values.














</section>


Expand Down
12 changes: 12 additions & 0 deletions src/difference.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* The absolute difference between two values.
*
* @param {number} a - The first value to check.
* @param {number} b - The second value to check.
* @return {number} The absolute difference between the two values.
*/
function difference (a, b) {
return Math.abs(a - b)
}

export { difference }
2 changes: 1 addition & 1 deletion src/math-toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ export { average } from './average'
export { isOdd } from './is-odd'
export { isEven } from './is-even'
export { percent } from './percent'
// difference
export { difference } from './difference'
7 changes: 7 additions & 0 deletions test/difference.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { difference } from '../src/math-toolbox'

describe('Calculate absolute difference', () => {
it('', () => {
expect(difference(10, 20)).toBe(10)
})
})

0 comments on commit 60f3e9f

Please sign in to comment.