Skip to content

Commit

Permalink
Merge pull request #52 from ays14/power
Browse files Browse the repository at this point in the history
add method to calculate power of a number
  • Loading branch information
Susmita-Dey committed Oct 24, 2022
2 parents ac65d01 + ceca770 commit 54f181d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
31 changes: 31 additions & 0 deletions docs/aFunc/doPower.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# doPower()

> This function is used to get the power/exponent of a number.
- @param {number} base `x` -> base number, whose power is calculated
- @param {number} exponent `y` -> power/index for the number
- @return {number} The power/exponent of the base number or say `x^y`

## Syntax

function(x, y) { ..code.. }

## Parameters

The function takes two parameters and return the output.

## Example

### Code:
```js
const calculator = require('all-round-calculator');
console.log(calculator.power(25,2));
```

### Output:
```bash
625
```

---

1 change: 1 addition & 0 deletions docs/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Currently we have almost 15+ functions in our npm package. Some of them are list
<!-- * [toOct()](aFunc/toOct.md):- Decimal to Octal -->
<!-- * [toTri()](aFunc/toTri.md):- Decimal to Trinary -->
* [doMod()](aFunc/doMod.md):- Get the modulus
* [doPower()](aFunc/doPower.md):- Get the power/exponent of a number

* ** Miscellaneous Functions**

Expand Down
11 changes: 11 additions & 0 deletions package/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ function getRandom() {
return Math.floor(Math.random() * 1000);
}

/**
* Calculate power of a number, as x^y
* @param {number} base x -> base number, whose power is calculated
* @param {number} exponent y -> power/index for the number
* @returns
*/
function doPower(base, exponent) {
return Math.pow(base, exponent);
}

// Export functions
module.exports = {
doAdd,
Expand Down Expand Up @@ -182,5 +192,6 @@ module.exports = {
doFactorial,
doMax,
doMin,
doPower,
calculatesin,
};

1 comment on commit 54f181d

@vercel
Copy link

@vercel vercel bot commented on 54f181d Oct 24, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.