Today I learned what
slice(1, -1) does.
I was looking up ways to (recursively) check if a string is a palindrome, and I came across a solution that used
slice() is a "returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array." Source
"A negative index can be used, indicating an offset from the end of the sequence. slice(-2) extracts the last two elements in the sequence."
Turns out, it's a count from the end, similarly to a positive number passed into the first parameter being a count from the beginning.
str = "margherita",
str.slice(1, -1 is equal to
"argherit". Nifty for all kinds of two-forked approaches. What ways would you use it?