3 String Based Javascript Interview Question

// REVERSE THE GIVEN STRING AND CHECK WEATHER IT IS PLAINDROME
const checkPlaindrome = (str) => {
    return str === str.split('').reverse().join('')
}

console.log(checkPlaindrome('WOW'))



// FIND THE LONGETS WORD IN SENTENCE

const finLongestWord = (str) => {
    let splited = str.split(' ')
    let longestWord = ''
    for (let i = 0; i < splited.length; i++) {
        if (longestWord.length < splited[i].length) {
            longestWord = splited[i]
        }
    }
    return longestWord
    // console.log(   longestWord)

}

console.log(finLongestWord('HERE IS THE SENTENCE'))


// REVERSE THE GIVEN STRING OF A SENTENCE WITHOUT CHANGING THE WORD SEQUENCE

const reverseWithSequence = (sen) => {
    let splited = sen.split(' ')
    let newVal = []
    for (let i = 0; i < splited.length; i++) {
         newVal.push(splited[i].split('').reverse().join('') )
    }
    return newVal.join(' ')
}

console.log(reverseWithSequence('NOW LETS SEE')) //WON STEL EES
console.log(reverseWithSequence('I NOW WON')) //WON STEL EES