Return reverse string


Posted by Christy on 2022-04-21

Description: Write a function named reverse that accepts a string and return the reversed string

Note: Don’t use the built-in function reverse()

function reverse(str) {
  let result = "";
  for (let i = str.length - 1; i >= 0; i--) {
    result += str[i];
  }
  return result;
}

console.log(reverse("abcd")); // dcba
console.log(reverse("12345aa")); // aa54321









Related Posts

打造後台管理系統的好幫手:Ant Design

打造後台管理系統的好幫手:Ant Design

[JavaScript ] ES7, ES8, ES10 有趣的 new features

[JavaScript ] ES7, ES8, ES10 有趣的 new features

SQL-injection lab(2)

SQL-injection lab(2)


Comments