Reverse a string in-place (without built-in methods) in JavaScript

 Example:

function reverse(str) {

  let arr = str.split("");

  for (let i = 0, j = arr.length - 1; i < j; i++, j--) {

    [arr[i], arr[j]] = [arr[j], arr[i]];

  }

  return arr.join("");

}

No comments:

Post a Comment

starter ASP.NET Core Web API project with example

Starter ASP.NET Core Web API project that follows all the best practices listed above. 🛠️ Starter Project Overview We’ll build a Produc...

Best for you