Reverse a String - Basic Algorithm Scripting - Free Code Camp

preview_player
Показать описание
In this basic algorithm scripting tutorial we reverse a string. This is another tutorial that makes up a series where I cover the FreeCodeCamp curriculum. Enjoy!
Рекомендации по теме
Комментарии
Автор

Man to watch you code is something on another level, to see you solve problems in real time is phenomenal.

EmmanesWilliams
Автор

Thank you Mr. Ian for showing us another way to get the accurate answer
return

zken
Автор

Here is a very simple solution and straight forward

- Use Spread Operator to copy the str and put it in an array
// output will be looking like this [ 'h', 'e', 'l', 'l', 'o' ]

- Use reverse() method built in Js to reverse the str
// [ 'o', 'l', 'l', 'e', 'h' ]

-Use join() method to join them
// o, l, l, e, h

- add ' ' in join method to remove the comma
the line will be looking like this let reverseArr = [...str].reverse().join(' ')
//output olleh

// Full solution
function reverseString(str) {

let reverseArr = [...str].reverse().join(' ')
return reverseArr
}



from Earth"));

tekken_king
Автор

Thank you for this, Useful Programmer! I could do this with for loop but I knew there is some other way of doing this and there it was: String methods!

masoudhabibzad
Автор

thank you for adding this! I know nothing about code and started FCC during quarantine. I like to think I'm a fairly intelligent individual but sometimes I just draw huge blanks when it comes to the algorithms. Does't help that I don't know any short cuts like that shown in the first solution!

saramoko
Автор


Split('') with convert each character into an array
Reverse () will reverse the array characters
Join('') will convert the array to strings.
(Caution: make sure there is no space between quotes, otherwise it will consider entire string instead of single character).

karthikjmoger
Автор

Great channel great explanations. thank you so much these videos help a ton.

jowurani
Автор

I'm wondering why all of a sudden they make the lesson at least three times as hard. We have not learnt either concept for either way to solve this problem?

deanlaz
Автор

Thanks for making this video! You rock!

MrWardo
Автор

I have a question. At first I was confused by 'let i = str.length - 1'... I get it, I think. Is it because string.length is a string method, and string methods return arrays which have index values? That's what it looks like. If so this is a big leap for me. The concept of string methods returning arrays and array methods returning strings....

moderncloth
Автор

I’m having a hard time finding out where to start when they don’t start the code for me. Like I don’t get what u mean when u say it goes around one and it’s four and then goes around again then it is three I don’t know if u get me but just really confused with the i is more than zero.
If u wouldn’t mind could u go through the whole meaning of the second code for me please would help so much thank you

paulfanning