Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reverse(text) {
- console.log(text);
- var wyraz = "";
- var odwroconyTekst = "";
- for(var i=0; i<text.length; i++) {
- //jesli nie napotkamy spacji dodajemy znaki do wyrazu
- if (text[i] != " " && i != text.length-1) {
- wyraz += text[i]
- }
- //ostatni znak wyrazu
- else if(i == text.length-1) {
- wyraz += text[i]
- for(var j=wyraz.length-1; j>=0; j--) {
- odwroconyTekst += wyraz[j];
- }
- wyraz = "";
- }
- //jesli napotkamy spacje
- else {
- for(var j=wyraz.length-1; j>=0; j--) {
- odwroconyTekst += wyraz[j];
- }
- odwroconyTekst+=" ";
- wyraz = "";
- }
- }
- return odwroconyTekst;
- }
- var text = "Tekst do przetestowania";
- var textTwo = "Hello World"
- console.log(reverse(text));
- console.log(reverse(textTwo));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement