1/1/2/2/3/3/4/4/5
should give 5 (just replace a thing with the next one)
The corresponding js in a functional paradigm for me is something like:
( state => state.replace( '4', '5' ) )
( state => state.replace( '3', '4' ) )
( state => state.replace( '2', '3' ) )
( state => state.replace( '1', '2' ) )
( '1' )