Skip to content

Commit

Permalink
Tipify nth root snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
Chalarangelo committed Feb 17, 2024
1 parent 44dea1b commit 19a6e2e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions content/snippets/js/s/nth-number-root.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
---
title: Nth root of number
type: snippet
title: Calculate the nth root of a number in JavaScript
shortTitle: Nth root of number
type: tip
language: javascript
tags: [math]
cover: tree-roots
dateModified: 2021-01-06
excerpt: Use `Math.pow()` to calculate the nth root of a given number in JavaScript.
dateModified: 2024-02-17
---

Calculates the nth root of a given number.
The **nth root** of a number `x` is a value that, when multiplied by itself `n` times, gives `x`. The nth root can also be expressed as a **power** of `x`, where `x ^ (1/n)` is equal to the nth root of `x`.

- Use `Math.pow()` to calculate `x` to the power of `1 / n` which is equal to the nth root of `x`.
Given this, we can use `Math.pow()` to calculate the nth root of a given number. Simply pass it the number `x` and a power of `1 / n`, and you'll get the nth root of `x`.

```js
const nthRoot = (x, n) => Math.pow(x, 1 / n);
Expand Down

0 comments on commit 19a6e2e

Please sign in to comment.