reverse string without using reverse function in javascript