javascript - Fill array to nearest multiple of 10 without going over -


been building encryption program. plan have characters mixed around (for example: 1234567890 encrypted 6345809127).

unfortunately mix in specific pattern need string multiple of ten, plan add character ' until string had length of multiple of ten. example, if input hello (5 characters) script insert ' until it's 10 characters, hello'''''.

any ideas on how this?

aside obvious problems of rolling own encryption (about million, billion times long answer here) you're asking quite simple.

var padstr = "''''''''''";  var input = "hello";    var output = input + padstr.substring(10-input.length);  console.log(output);  console.log(output.length);

that covers input string up 10, not multiples of 10. thats more complex though:

var padstr = "''''''''''";  var input = "helloworldlongerthan10";    var output = input + padstr.substring(input.length%10);  console.log(output);  console.log(output.length);


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -