Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(input) {
- let reverseString = '';
- for (let i = input.length - 1; i >= 0; i--){
- reverseString += input[i];
- }
- console.log(reverseString);
- }
- Решение с методи:
- function solve(input) {
- // Примерен вход: 'abc'
- let reverseString = input.split(""); // Масив от чарове: ['a','b','c']
- reverseString.reverse(); // Обръща елементите:['c','b','a']
- reverseString = reverseString.join("");// Слепва елементите по "": 'cba'
- console.log(reverseString);
- }
- Или така:
- function solve(input) {
- console.log(input.split("").reverse().join(""));
- //или: console.log([...input].reverse().join(""));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement