Skip to content

Arrays and Strings #5

Closed Answered by anburocky3
ARSGowtham asked this question in Q&A
Discussion options

You must be logged in to vote

You can do like this:

const message = 'Hello World'

// Method: 1 using reduce()
const method1 = Array.from(message).reduce((accumulator, currentValue) => {
  return [currentValue].concat(accumulator)
})

console.log('Method 1:', method1.join(''))

// Method: 2 using reverse()
const method2 = Array.from(message).reverse()

console.log('Method 2:', method2.join(''))

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by anburocky3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants