-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSort the Gift Code.js
More file actions
23 lines (18 loc) · 1.16 KB
/
Sort the Gift Code.js
File metadata and controls
23 lines (18 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Happy Holidays fellow Code Warriors!
// Santa's senior gift organizer Elf developed a way to represent up to 26 gifts by assigning a unique alphabetical character to each gift. After each gift was assigned a character, the gift organizer Elf then joined the characters to form the gift ordering code.
// Santa asked his organizer to order the characters in alphabetical order, but the Elf fell asleep from consuming too much hot chocolate and candy canes! Can you help him out?
// Sort the Gift Code
// Write a function called sortGiftCode/sort_gift_code/SortGiftCode that accepts a string containing up to 26 unique alphabetical characters, and returns a string containing the same characters in alphabetical order.
// Examples:
// sortGiftCode( 'abcdef' ); //=> returns 'abcdef'
// sortGiftCode( 'pqksuvy' ); //=> returns 'kpqsuvy'
// sortGiftCode( 'zyxwvutsrqponmlkjihgfedcba' ); //=> returns 'abcdefghijklmnopqrstuvwxyz'
function sortGiftCode(code) {
return code.split('').sort().join('')
}
console.log(sortGiftCode('abcdef'), 'abcdef')
console.log(sortGiftCode('pqksuvy'), 'kpqsuvy')
console.log(
sortGiftCode('zyxwvutsrqponmlkjihgfedcba'),
'abcdefghijklmnopqrstuvwxyz'
)