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

Angular's new httpResource and a bonus hidden feature

  The first   release candidate   for   Angular 19.2   is out, and it includes the new experimental   httpResource . This is essentially a s...

Best for you