String alignment using dynamic programing in javascript