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

Advanced Angular Interview Questions with Code Examples

Advanced Angular Interview Questions with Code Examples Component Communication & State Management 1. Parent-Child Communication with ...

Best for you