mirror of
https://github.com/google/blockly.git
synced 2026-01-08 17:40:09 +01:00
Fix Dart and PHP lists_sort.
Add generator tests.
This commit is contained in:
@@ -321,14 +321,13 @@ Blockly.Dart['lists_sort'] = function(block) {
|
||||
['List ' + Blockly.Dart.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'(list, type, direction) {',
|
||||
' var compareFuncs = {',
|
||||
' "NUMERIC": (a, b) => direction * ',
|
||||
' double.parse(a.toString()).compareTo(double.parse(b.toString())),',
|
||||
' "NUMERIC": (a, b) => direction * a.compareTo(b),',
|
||||
' "TEXT": (a, b) => direction * a.toString().compareTo(b.toString()),',
|
||||
' "IGNORE_CASE": ',
|
||||
' (a, b) => direction * ',
|
||||
' a.toString().toLowerCase().compareTo(b.toString().toLowerCase())',
|
||||
' };',
|
||||
' list = (new List.from(list))', // Clone the list.
|
||||
' list = new List.from(list);', // Clone the list.
|
||||
' var compare = compareFuncs[type];',
|
||||
' list.sort(compare);',
|
||||
' return list;',
|
||||
|
||||
@@ -366,14 +366,14 @@ Blockly.PHP['lists_sort'] = function(block) {
|
||||
'lists_sort', [
|
||||
'function ' + Blockly.PHP.FUNCTION_NAME_PLACEHOLDER_ +
|
||||
'($list, $type, $direction) {',
|
||||
' $sortFuncs = array(',
|
||||
' "NUMERIC" => "sort",',
|
||||
' "TEXT" => "natsort",',
|
||||
' "IGNORE_CASE" => "natcasesort"',
|
||||
' $sortCmpFuncs = array(',
|
||||
' "NUMERIC" => "strnatcasecmp",',
|
||||
' "TEXT" => "strcmp",',
|
||||
' "IGNORE_CASE" => "strcasecmp"',
|
||||
' );',
|
||||
' $sort = $sortFuncs[$type];',
|
||||
' $sortCmp = $sortCmpFuncs[$type];',
|
||||
' $list2 = $list;', // Clone list.
|
||||
' $sort($list2);',
|
||||
' usort($list2, $sortCmp);',
|
||||
' if ($direction == -1) {',
|
||||
' $list2 = array_reverse($list2);',
|
||||
' }',
|
||||
|
||||
Reference in New Issue
Block a user