Update misc.js

it had some problem with len of string 0 and slicing from 0 to -0 , or calculating len of ''.
now is ok, rects went crazy and i didn't notice.