Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 'Return the first M multiples of N'
Add 'Return the first M multiples of N' kata
- Loading branch information
1 parent
a882c30
commit d8c5902
Showing
3 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import multiples from '.'; | ||
|
||
describe('multiples', () => { | ||
it('should return an array of the first `m` multiples of `n`', () => { | ||
expect.assertions(1); | ||
|
||
expect(multiples(3, 5)).toStrictEqual([5, 10, 15]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
function multiples(m: number, n: number): number[] { | ||
return Array.from({ length: m }, (_, index) => (index + 1) * n); | ||
} | ||
|
||
export default multiples; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# [Return the first M multiples of N](https://www.codewars.com/kata/593c9175933500f33400003e) | ||
|
||
Implement a function, `multiples(m, n)`, which returns an array of the first `m` multiples of the real number `n`. Assume that `m` is a positive integer. | ||
|
||
Ex. | ||
|
||
``` | ||
multiples(3, 5.0) | ||
``` | ||
|
||
should return | ||
|
||
``` | ||
[5.0, 10.0, 15.0] | ||
``` | ||
|
||
--- | ||
|
||
## Tags | ||
|
||
- Algorithms | ||
- Fundamentals | ||
- Logic | ||
- Mathematics | ||
- Numbers |