Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize #1610

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Optimize #1610

wants to merge 2 commits into from

Conversation

GeorgCantor
Copy link

@GeorgCantor GeorgCantor commented Nov 19, 2023

Using lastIndexOf:
Instead of splitting the string into an array and then joining it back together, we find the index of the last period (.) in the string using lastIndexOf. This is more efficient as it avoids unnecessary array creation.

Using substring:
If a period is found (lastIndex != -1), we use substring to extract everything before the last period. This is a direct operation on the string and avoids the overhead of creating an intermediate list.

Handling Edge Cases:
If there is no period in the string, we return an empty string. This ensures that our function behaves predictably regardless of input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants