-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import GeeProcess from '../processgraph/process.js'; | ||
|
||
export default class sort extends GeeProcess { | ||
|
||
executeSync(node) { | ||
const ee = node.ee; | ||
let data = node.getArgumentAsEE("data"); | ||
const value = node.getArgument("asc", true); | ||
|
||
if (data instanceof ee.List) { | ||
data = data.sort(); | ||
if (!value) { | ||
data = data.reverse(); | ||
} | ||
return data; | ||
} | ||
else if (data instanceof ee.Array) { | ||
data = data.sort(); | ||
if (!value) { | ||
// todo: how to sort in descending order? | ||
throw node.invalidArgument("asc", "Data of type ee.Array can't be sorted in descending order."); | ||
} | ||
return data.sort(); | ||
} | ||
|
||
throw node.invalidArgument("data", "Unsupported data type."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"id": "sort", | ||
"summary": "Sort data", | ||
"description": "Sorts an array into ascending (default) or descending order.\n\n**Remarks:**\n\n* The ordering of ties is implementation-dependent.\n* Temporal strings can *not* be compared based on their string representation due to the time zone/time-offset representations.", | ||
"categories": [ | ||
"arrays", | ||
"sorting" | ||
], | ||
"parameters": [ | ||
{ | ||
"name": "data", | ||
"description": "An array with data to sort.", | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"anyOf": [ | ||
{ | ||
"type": "number" | ||
}, | ||
{ | ||
"type": "null" | ||
}, | ||
{ | ||
"type": "string", | ||
"format": "date-time", | ||
"subtype": "date-time" | ||
}, | ||
{ | ||
"type": "string", | ||
"format": "date", | ||
"subtype": "date" | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
{ | ||
"name": "asc", | ||
"description": "The default sort order is ascending, with smallest values first. To sort in reverse (descending) order, set this parameter to `false`.", | ||
"schema": { | ||
"type": "boolean" | ||
}, | ||
"default": true, | ||
"optional": true | ||
} | ||
], | ||
"returns": { | ||
"description": "The sorted array.", | ||
"schema": { | ||
"type": "array", | ||
"items": { | ||
"anyOf": [ | ||
{ | ||
"type": "number" | ||
}, | ||
{ | ||
"type": "null" | ||
}, | ||
{ | ||
"type": "string", | ||
"format": "date-time", | ||
"subtype": "date-time" | ||
}, | ||
{ | ||
"type": "string", | ||
"format": "date", | ||
"subtype": "date" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |