Skip to content

Commit

Permalink
Descending Order
Browse files Browse the repository at this point in the history
  • Loading branch information
PheRum committed Jun 13, 2024
1 parent cd73572 commit 38bb5ee
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
10 changes: 10 additions & 0 deletions 7_kyu/Descending Order/README.md
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`
12 changes: 12 additions & 0 deletions 7_kyu/Descending Order/index.test.ts
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);
});
});
8 changes: 8 additions & 0 deletions 7_kyu/Descending Order/index.ts
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(""));
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

### Katas solved

`Total`: 65 \
`Total`: 66 \
`8_kyu`: 51 \
`7_kyu`: 10 \
`7_kyu`: 11 \
`6_kyu`: 4 \
`5_kyu`: 0 \
`4_kyu`: 0 \
Expand Down
1 change: 0 additions & 1 deletion kata.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
8 kyu - Calculate average - https://www.codewars.com/kata/57a2013acf1fa5bfc4000921
8 kyu - Reversed sequence - https://www.codewars.com/kata/5a00e05cc374cb34d100000d
8 kyu - Grasshopper - Messi goals function - https://www.codewars.com/kata/55f73be6e12baaa5900000d4
7 kyu - Descending Order - https://www.codewars.com/kata/5467e4d82edf8bbf40000155
8 kyu - Basic Mathematical Operations - https://www.codewars.com/kata/57356c55867b9b7a60000bd7
8 kyu - Grasshopper - Terminal game move function - https://www.codewars.com/kata/563a631f7cbbc236cf0000c2
8 kyu - Convert a Boolean to a String - https://www.codewars.com/kata/551b4501ac0447318f0009cd
Expand Down

0 comments on commit 38bb5ee

Please sign in to comment.