CommandHelper icon indicating copy to clipboard operation
CommandHelper copied to clipboard

Add string_compare function and support integer return type in array_sort function

Open Pieter12345 opened this issue 2 years ago • 1 comments

  • Export functionality of Java's String.compareTo(String) in MethodScript API.
  • Support integer return type in array_sort closure.

This is useful to convert hacky code such as:

array @arr = array(array('key': 'Hello'), array('key': 'World'), array('key': 'Aaahhh'));
@arr = array_sort(@arr, closure(@left, @right) {
    return(array_sort(array(@left['key'], @right['key']), 'STRING')[0] === @right['key']);
});

into:

array @arr = array(array('key': 'Hello'), array('key': 'World'), array('key': 'Aaahhh'));
@arr = array_sort(@arr, closure(@left, @right) {
    return(string_compare(@left['key'], @right['key']));
});

Pieter12345 avatar Dec 17 '23 04:12 Pieter12345

As a result from a discussion with @PseudoKnight, we decided that this PR should also include a string_compare_ic() function that works the same as string_compare(), except that it ignores casing.

Pieter12345 avatar Jan 31 '24 18:01 Pieter12345