We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bb1a5fb commit 2ebe65bCopy full SHA for 2ebe65b
Maths/Pow.js
@@ -0,0 +1,11 @@
1
+// Returns the value of x to the power of y
2
+
3
+const pow = (x, y) => {
4
+ let result = 1
5
+ for (let i = 1; i <= y; i++) {
6
+ result *= x
7
+ }
8
+ return result
9
+}
10
11
+export { pow }
Maths/test/Pow.test.js
@@ -0,0 +1,15 @@
+import { pow } from '../Pow'
+describe('Pow', () => {
+ it('should return 1 for numbers with exponent 0', () => {
+ expect(pow(2, 0)).toBe(1)
+ })
+ it('should return 0 for numbers with base 0', () => {
+ expect(pow(0, 23)).toBe(0)
12
+ it('should return the base to the exponent power', () => {
13
+ expect(pow(24, 4)).toBe(331776)
14
15
+})
0 commit comments