@aloyschen
2017-10-17T15:42:32.000000Z
字数 877
阅读 238
CodeWars
Task
Write a function nico/nico() that accepts two parameters:
key/message - string to encode
and encodes the message using the key.
First create a numeric key basing on a provided key by assigning each letter position in which it is located after setting the letters from key in an alphabetical order.
For example, for the key crazy we will get 23154 because of acryz (sorted letters from the key).
Let's encode secretinformation using our crazy key.
2 3 1 5 4---------s e c r et i n f or m a t io nAfter using the key:1 2 3 4 5---------c s e e rn t i o fa r m i to nNotes
The message is never shorter than the key.
Examples
nico("crazy", "secretinformation") => "cseerntiofarmit on "nico("abc", "abcd") => "abcd "nico("ba", "1234567890") => "2143658709"nico("key", "key") => "eky"Check the test cases for more samples.