reverse string without using inbuilt function javascript