Hacker News new | ask | show | jobs
by jameshart 3743 days ago
Best practice for performance for large left-pad jobs is to call the service recursively using mapreduce. Remember that left-pad(str,pad,n) is equal to left-pad(left-pad(str,pad,n/2),left-pad("",pad,n/2),n). This should run in logarithmic time and is highly parallelizable.

If you don't like the "" magic string in there you could replace it with a call to left-pad(null, null,0).

3 comments

You should be using emptystring.io instead of the "magic string" or a "null, null" hack.
oh god it's too real
Poe's law for programming culture extremists
if you put https://api.left-pad.io/?len=1017 or anything higher than 1016 it says:

{"errorMessage":"len exceeds 1007 characters. Contact a left-pad.io sales engineer for an enterprise license","errorType":"Error","stackTrace":["exports.handler (/var/task/index.js:33:22)"]}

wow. they even have an enterprise sales engineer! :)

Shouldn't it be leftpad(leftpad (str,pad,n/2),leftpad("",pad,n/2),1)?