Created
March 11, 2025 16:11
-
-
Save AlvisonHunterArnuero/5296c6dbd5272b0a31c702137d7cdf2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://www.codewars.com/kata/586efc2dcf7be0f217000619/train/javascript | |
const reverseSlice = s => { | |
// First, split the string `s` into an array of characters, reverse the order, | |
// and join them back into a new string. | |
const reversedStr = s.split("").reverse().join(""); | |
// Iterate over the reversed string using the `map` method. | |
// On each iteration, return a substring that starts from the current index `i` | |
// to the end of `reversedStr`. This effectively creates a progressively smaller | |
// set of substrings, where each new element in the resulting array is a | |
// truncated version of the reversed string. | |
return [...reversedStr].map((_, i) => | |
reversedStr.substring(i) | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment