-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
c049f15
commit ae9c443
Showing
4 changed files
with
104 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
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,24 @@ | ||
# rollCall | ||
|
||
Interview question of the [issue #381 of rendezvous with cassidoo](https://buttondown.com/cassidoo/archive/how-beautiful-it-is-to-get-up-and-go-do-something/). | ||
|
||
## The Question | ||
|
||
**Santa is conducting his daily roll call for the reindeer, but the printer has mistakenly printed all their names backwards. To take attendance properly, he urgently needs a tool to reverse the reindeer names and put them in alphabetical order! Can you help Santa?** | ||
|
||
Example: | ||
|
||
```js | ||
rollCall(["yzneT","ydissaC","enimA"]) | ||
["Amine","Cassidy","Tenzy"] | ||
|
||
rollCall(["rennuD","nexiV","recnarP","temoC","neztilB","recnaD","diduC","rehsaD","hploduR"]) | ||
["Blitzen","Comet","Cupid","Dancer","Dasher","Donner","Prancer","Rudolph","Vixen"] | ||
|
||
rollCall(["A","B","C"]) | ||
["A","B","C"] | ||
``` | ||
|
||
## Installing & Running | ||
|
||
Just `pnpm i` to install all dependencies and then `pnpm t` to run the tests! |
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,57 @@ | ||
import { rollCall } from './rollCall'; | ||
|
||
describe('#rollCall', () => { | ||
it('should reverse names and sort them alphabetically', () => { | ||
expect(rollCall(['yzneT', 'ydissaC', 'enimA'])).toStrictEqual(['Amine', 'Cassidy', 'Tenzy']); | ||
}); | ||
|
||
it('should handle a list of all the reindeer names', () => { | ||
expect( | ||
rollCall([ | ||
'rennoD', | ||
'nexiV', | ||
'recnarP', | ||
'temoC', | ||
'neztilB', | ||
'recnaD', | ||
'dipuC', | ||
'rehsaD', | ||
'hploduR', | ||
]), | ||
).toStrictEqual([ | ||
'Blitzen', | ||
'Comet', | ||
'Cupid', | ||
'Dancer', | ||
'Dasher', | ||
'Donner', | ||
'Prancer', | ||
'Rudolph', | ||
'Vixen', | ||
]); | ||
}); | ||
|
||
it('should handle single-letter names without any change', () => { | ||
expect(rollCall(['A', 'B', 'C'])).toStrictEqual(['A', 'B', 'C']); | ||
}); | ||
|
||
it('should handle an empty list gracefully', () => { | ||
expect(rollCall([])).toStrictEqual([]); | ||
}); | ||
|
||
it('should handle a single name correctly', () => { | ||
expect(rollCall(['adniL'])).toStrictEqual(['Linda']); | ||
}); | ||
|
||
it('should handle names with mixed cases correctly', () => { | ||
expect(rollCall(['AIz', 'aRiD', 'eMmA'])).toStrictEqual(['AmMe', 'DiRa', 'zIA']); | ||
}); | ||
|
||
it('should handle duplicate reversed names and sort them properly', () => { | ||
expect(rollCall(['adnaL', 'adnaL'])).toStrictEqual(['Landa', 'Landa']); | ||
}); | ||
|
||
it('should handle names that are palindromes (no visible change after reversing)', () => { | ||
expect(rollCall(['anna', 'bob', 'otto'])).toStrictEqual(['anna', 'bob', 'otto']); | ||
}); | ||
}); |
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,22 @@ | ||
/* | ||
Santa is conducting his daily roll call for the reindeer, | ||
but the printer has mistakenly printed all their names backwards. | ||
To take attendance properly, | ||
he urgently needs a tool to reverse the reindeer names and put them in alphabetical order! | ||
Can you help Santa? | ||
Example: | ||
rollCall(["yzneT","ydissaC","enimA"]) | ||
["Amine","Cassidy","Tenzy"] | ||
rollCall(["rennuD","nexiV","recnarP","temoC","neztilB","recnaD","diduC","rehsaD","hploduR"]) | ||
["Blitzen","Comet","Cupid","Dancer","Dasher","Donner","Prancer","Rudolph","Vixen"] | ||
rollCall(["A","B","C"]) | ||
["A","B","C"] | ||
*/ | ||
|
||
export function rollCall(names: string[]): string[] { | ||
return names.map(name => name.split('').reverse().join('')).sort(); | ||
} |