From f18f61f5b2765e55651fcdff82f627ee7b913d4d Mon Sep 17 00:00:00 2001 From: Chalarangelo Date: Wed, 6 Jan 2021 22:47:48 +0200 Subject: [PATCH] Add nthRoot --- snippets/nthRoot.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 snippets/nthRoot.md diff --git a/snippets/nthRoot.md b/snippets/nthRoot.md new file mode 100644 index 000000000..d9e55a09d --- /dev/null +++ b/snippets/nthRoot.md @@ -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 +```