Custom function to replace state with abbreviation

Custom function to replace state with abbreviation

I'd like to make sure our data is consistent.  Right now some states are spelled out and others are abbreviation.  I know I can do a mass update but I'm hoping to automate this.

I'd like to create a function that will replace spelled out states with their abbreviation.  What would the function for that look like?