From 2248ce7a05352bb1cf6c35660b465136fa67585b Mon Sep 17 00:00:00 2001 From: Tajanae Boone Date: Thu, 3 Dec 2020 09:40:07 -0500 Subject: [PATCH] reverse strings --- index.html | 14 ++++++++++++++ strings.js | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 index.html create mode 100644 strings.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..763e3d1 --- /dev/null +++ b/index.html @@ -0,0 +1,14 @@ + + + + + + Document + + + + + + + + \ No newline at end of file diff --git a/strings.js b/strings.js new file mode 100644 index 0000000..4f490e6 --- /dev/null +++ b/strings.js @@ -0,0 +1,21 @@ + + +function reverseString(str) { + // Step 1. Use the split() method to return a new array + let splitString = str.split(""); // var splitString = "hello".split(""); + // ["h", "e", "l", "l", "o"] + + // Step 2. Use the reverse() method to reverse the new created array + let reverseArray = splitString.reverse(); // var reverseArray = ["h", "e", "l", "l", "o"].reverse(); + // ["o", "l", "l", "e", "h"] + + // Step 3. Use the join() method to join all elements of the array into a string + let joinArray = reverseArray.join(""); // var joinArray = ["o", "l", "l", "e", "h"].join(""); + // "olleh" + + //Step 4. Return the reversed string + return joinArray; // "olleh" +} + +reverseString("Hello"); +reverseString("SuperDeeDuper"); \ No newline at end of file