Negative Indexes in Nth(), Slice(), Splice(), Left()

In many programming languages (eg: JavaScript, Python, Java, C#, Clojure, etc.) you can use a negative index to select items in arrays or characters in text counting from the end of the array or string.

Positive indexes count from the start. Negative indexes count from the end.

So I tried this out in Coda and it works! At least for the Nth(), Slice(), Splice() and Left() functions.
Even though this feature is not included in the documentation.

It does not work for Right() or Middle() alas.



I’ve also noticed that you can use negative numbers in the rounding formulas. -1 would round to closest 10, -2 to closest 100, etc

Easter eggs?


Good to know! Hmm. Wouldn’t it be cool if the Coda documentation on formulas allowed us to add comments to them so they would know where updates were needed. Hmmm…


Right Peit! I also noticed it and use it all the time. I think I got the idea initially from Excel and it still works here in Coda


Great post!!!

One more formula to add where I use negatives, Workday(). If you know the end date, or launch date, you can count backwards to the day you need to start by adding a negative to the number of workdays required. You can multiply by -1 but I thought it was kind of cool that you could go back and just add the minus sign next to a variable.


The second example here is using a negative in the Slice() formula to split first and last names. You can get creative with this trick!