Skip to content

Instantly share code, notes, and snippets.

@AlvisonHunterArnuero
Created March 11, 2025 16:11
Show Gist options
  • Save AlvisonHunterArnuero/5296c6dbd5272b0a31c702137d7cdf2d to your computer and use it in GitHub Desktop.
Save AlvisonHunterArnuero/5296c6dbd5272b0a31c702137d7cdf2d to your computer and use it in GitHub Desktop.
// 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