Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit 67ef2b4

Browse files
sinahwzKent C. Dodds
authored andcommitted
feat: add a feature to find square roots (#84)
a new feature/function which help to calculate the square root of any number given as input to it Closes #83
1 parent 1a2be2c commit 67ef2b4

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import square from './square'
2525
import sum from './sum'
2626
import dec2bin from './dec2bin'
2727
import searchAndReplace from './search-and-replace'
28+
import sqrt from './sqrt'
2829

2930
export {
3031
initArray,
@@ -53,4 +54,5 @@ export {
5354
sum,
5455
dec2bin,
5556
searchAndReplace,
57+
sqrt,
5658
}

src/sqrt.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default sqrt
2+
3+
/**
4+
* This method will perform square root operation.
5+
*
6+
* @param {Number} num - number to calculate its square root
7+
* @return {Number} - Result of the square root operation
8+
*/
9+
10+
function sqrt(num) {
11+
return Math.sqrt(num)
12+
}

test/sqrt.test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import test from 'ava'
2+
import {sqrt} from '../src'
3+
4+
test('Square root of a number', t => {
5+
const number = 25
6+
const expected = 5
7+
const actual = sqrt(number)
8+
t.deepEqual(actual, expected)
9+
})
10+

0 commit comments

Comments
 (0)