[关闭]
@aloyschen 2017-10-17T15:42:32.000000Z 字数 877 阅读 238

CodeWars 刷题总结

CodeWars


Basic Nico variation

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.

  1. 2 3 1 5 4
  2. ---------
  3. s e c r e
  4. t i n f o
  5. r m a t i
  6. o n
  7. After using the key:
  8. 1 2 3 4 5
  9. ---------
  10. c s e e r
  11. n t i o f
  12. a r m i t
  13. o n
  14. Notes

The message is never shorter than the key.

Examples

  1. nico("crazy", "secretinformation") => "cseerntiofarmit on "
  2. nico("abc", "abcd") => "abcd "
  3. nico("ba", "1234567890") => "2143658709"
  4. nico("key", "key") => "eky"
  5. Check the test cases for more samples.

知识点

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注