-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
32 additions
and
3 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,10 @@ | ||
## Descending Order | ||
|
||
https://www.codewars.com/kata/5467e4d82edf8bbf40000155 | ||
|
||
Your task is to make a function that can take any non-negative integer as an argument and return it with its digits in descending order. Essentially, rearrange the digits to create the highest possible number. | ||
|
||
**Examples**: | ||
Input: `42145` Output: `54421` | ||
Input: `145263` Output: `654321` | ||
Input: `123456789` Output: `987654321` |
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,12 @@ | ||
import { descendingOrder } from "./index"; | ||
|
||
describe("Tests", () => { | ||
it("Testing for fixed tests", () => { | ||
expect(descendingOrder(0)).toBe(0); | ||
expect(descendingOrder(1)).toBe(1); | ||
expect(descendingOrder(111)).toBe(111); | ||
expect(descendingOrder(15)).toBe(51); | ||
expect(descendingOrder(1021)).toBe(2110); | ||
expect(descendingOrder(123456789)).toBe(987654321); | ||
}); | ||
}); |
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,8 @@ | ||
export function descendingOrder(n: number): number { | ||
const numbers = String(n) | ||
.split("") | ||
.map((n) => +n) | ||
.sort((a, b) => b - a); | ||
|
||
return parseInt(numbers.join("")); | ||
} |
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
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