Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Maths/Pow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Returns the value of x to the power of y

const pow = (x, y) => {
let result = 1
for (let i = 1; i <= y; i++) {
result *= x
}
return result
}

export { pow }
15 changes: 15 additions & 0 deletions Maths/test/Pow.test.js
Original file line number Diff line number Diff line change
@@ -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)
})

it('should return the base to the exponent power', () => {
expect(pow(24, 4)).toBe(331776)
})
})