I'm trying to solve this issue in javascript. I understand in javascript functions (for the most part) can only return one word. I'm trying to figure out how to return multiply words within a function. If theres another way besides a function that I can solve this i'm open to that too.
function aListOfPalindromeWords (str){
const words = "a aa aaa aah aahed aahing aah saal aalii aaliis aals aam";
const myWords = words.split(" ");
var reversedStr = "";
for (let i = 0; i < myWords.length; i++){
for (let j = myWords[i].length; i >=0; i--){
reversedStr += myWords[i];
> {
if (reversedStr === myWords[i]);
> {
return myWords[i];
> }
> }
> }
> }
> }
console.log(aListOfPalindromeWords ());
You can either return an array or a string which will contain word which are palindrome.
You can do this using
split,filter,reverseandjoin.If you want to return string which contains only palindrome words then you can return
result.join(" "), which will return string.