Friday, 21 February 2020

Reverse the String

Reverse the String


Objective

Reverse the provided string using the built-in function.


Solution


For this solution, you will use three methods: the String.prototype.split() method, the Array.prototype.reverse() method and the Array.prototype.join() method.


  • The split() method splits a String object into an array of the string by separating the string into substrings.
  • The reverse() method reverses an array in place. The first array element becomes the last and the last becomes the first.
  • The join() method joins all elements of an array into a string.



Code

Here’s my solution, with embedded comments:


I hope you found this helpful.
Cheers :)

No comments:

Post a Comment

Diagonal Difference

Diagonal Difference Objective Given a square matrix, calculate the absolute difference between the sums of its diagonals. Descripti...