Add nthRoot

This commit is contained in:
Chalarangelo
2021-01-06 22:47:48 +02:00
parent 20253238c8
commit f18f61f5b2

16
snippets/nthRoot.md Normal file
View File

@ -0,0 +1,16 @@
---
title: nthRoot
tags: math,beginner
---
Calculates the nth root of a given number.
- Use `Math.pow()` to calculate `x` to the power of `1/n` which is equal to the nth root of `x`.
```js
const nthRoot = (x, n) => Math.pow(x, 1 / n);
```
```js
nthRoot(32, 5); // 2
```