We're a place where coders share, stay up-to-date and grow their careers.
How about this solution?
const reverse = ([...str]) => { const len = str.length; for(let i=0;i<len/2;i++){ [str[i],str[len-i]] = [str[len-i],str[i]]; } return str.join(''); }
Or not so optimized but shorter code:
const reverse2 = ([...str]) => str.map((ch,i)=>str[str.length-1-i]).join('');
How about this solution?
Or not so optimized but shorter code: