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

string_unique_chars #111

Open
Appsurdgames opened this issue Dec 13, 2024 · 2 comments
Open

string_unique_chars #111

Appsurdgames opened this issue Dec 13, 2024 · 2 comments
Labels
feature ✨ For feature requests and implementations

Comments

@Appsurdgames
Copy link

Appsurdgames commented Dec 13, 2024

To get all unique characters from a given string.

My sample implementation places all unique characters in an array, but we could also change the function name to string_remove_duplicates and return a string instead. What would you prefer?

/// @param {str}	string		The string to use
///
/// @description	Gets all unique characters from a string and places them in an array
/// @date			2024-05-28
/// @copyright		Appsurd

function string_unique_chars(_input_str)
{
	var array_unique_chars = [];
	for (var i = 1; i <= string_length(_input_str); i++)
	{
		var char = string_char_at(_input_str, i);
		if (array_contains(array_unique_chars, char) == false)
		{
			array_push(array_unique_chars, char);
		}
	}
	return array_unique_chars;
}```
@Alphish
Copy link
Owner

Alphish commented Dec 13, 2024

Could you provide an example real life case where this would be useful? At the moment I don't know what the scenario is, and if the given problem couldn't be solved better with an alternative approach.

Other than that, if this was implemented, it would likely be based on string_foreach, because string_char_at gets slower the longer the string is (quirk of storing strings in memory in UTF8 format).

@Alphish Alphish added the feature ✨ For feature requests and implementations label Dec 13, 2024
@Appsurdgames
Copy link
Author

To be fair, I cannot really remember where I used this for. It's more to the specific-side of all functions that I proposed, so I'm fine dropping the proposal if people are not interested in this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ✨ For feature requests and implementations
Projects
None yet
Development

No branches or pull requests

2 participants