# startOfSuffix() can be much simplified by using \`.lastIndex\`?

**URL:** <https://forums.swift.org/t/startofsuffix-can-be-much-simplified-by-using-lastindex/48087>\
**Category:** Algorithms\
**Created:** [May 11, 2021, 12:25am UTC](https://forums.swift.org/t/startofsuffix-can-be-much-simplified-by-using-lastindex/48087 "2021-05-11T00:25:45Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [May 11, 2021, 2:12am UTC](https://forums.swift.org/t/startofsuffix-can-be-much-simplified-by-using-lastindex/48087/2 "2021-05-11T02:12:48Z")

</div>

This issue of implementation has been discussed:

> [@Add \`SortedArray\`, \`SortedSet\` and \`SortedDictionary\` with binary search](https://forums.swift.org/t/add-sortedarray-sortedset-and-sorteddictionary-with-binary-search/47303/6):
>
> > [@Add \`SortedArray\`, \`SortedSet\` and \`SortedDictionary\` with binary search](https://forums.swift.org/t/add-sortedarray-sortedset-and-sorteddictionary-with-binary-search/47303/5):
> >
> > It seems rather antithetical to the goal of “use the standard algorithms that are already written” when both the standard library and the Algorithms package choose to spend a dozen lines reimplementing something twice (with complicated nested loops whose exit conditions are hidden in the middle, no less!), that would be easy one-liners using the standard index-finding methods.
> 
> Programming isn't turtles all the way down -- the cost of providing really nice abstractions is that somebody somewhere needs to implement them in terms of more primitive tools. The engineers working on the stdlib and these packages sweat the details of implementing these so that others don't have to.

---

_[View the full topic](https://forums.swift.org/t/startofsuffix-can-be-much-simplified-by-using-lastindex/48087)._
