proper cutoff in javascript