#2000. Reverse Prefix of Word

RMAG news

https://leetcode.com/problems/reverse-prefix-of-word/?envType=daily-question&envId=2024-05-01

/**
* @param {string} word
* @param {character} ch
* @return {string}
*/

var reversePrefix = function (word, ch) {
if (word.indexOf(ch) === 1) return word

word = word.split()
let idx = word.indexOf(ch)
let reverse = word.splice(0, idx + 1)
reverse.reverse()

let newWord = reverse.concat(word)

return newWord.join()
};

Lasă un răspuns

Adresa ta de email nu va fi publicată. Câmpurile obligatorii sunt marcate cu *