You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
}```
The text was updated successfully, but these errors were encountered:
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).
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
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?The text was updated successfully, but these errors were encountered: