Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method to calculate power of a number #52

Merged
merged 3 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -137,6 +137,16 @@ function percentage(partialValue, totalValue) {
return (100 * partialValue) / totalValue;
}

/**
* 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 @@ -165,4 +175,5 @@ module.exports = {
doFactorial,
doMax,
doMin,
doPower,
};