Just starting out with javascript and struggling to merge arrays. I attempted to reverse words manually, but ended up with unexpected results. Here is the code snippet:
function reverseString(kata) {
let currentString = kata;
let newString = '';
let cetakKata = '';
for (let i = kata.length - 1; i >= 0; i--) {
newString = newString + currentString[i];
}
console.log(newString);
const splitNewString = newString.split(' ')
console.log(splitNewString);
for (let i = 0; i < splitNewString.length; i++) {
const cetak = splitNewString[i].split('').reverse().join('')
cetakKata = cetakKata + cetak
}
console.log(cetakKata);
}
reverseString('hello java script');
Here is my current output:
scriptjavahello
The desired output is:
script java hello