| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -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 } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + import { pow } from '../Pow' | ||
| 2 | + | ||
| 3 | + describe('Pow', () => { | ||
| 4 | + it('should return 1 for numbers with exponent 0', () => { | ||
| 5 | + expect(pow(2, 0)).toBe(1) | ||
| 6 | + }) | ||
| 7 | + | ||
| 8 | + it('should return 0 for numbers with base 0', () => { | ||
| 9 | + expect(pow(0, 23)).toBe(0) | ||
| 10 | + }) | ||
| 11 | + | ||
| 12 | + it('should return the base to the exponent power', () => { | ||
| 13 | + expect(pow(24, 4)).toBe(331776) | ||
| 14 | + }) | ||
| 15 | + }) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments