feat: add List.sort and List.sortBy functions (issue 9)
Add sorting support to the List module across all backends: - List.sort for natural ordering (Int, Float, String, Bool, Char) - List.sortBy for custom comparator-based sorting Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1812,6 +1812,18 @@ impl JsBackend {
|
||||
end, start, start
|
||||
))
|
||||
}
|
||||
"sort" => {
|
||||
let list = self.emit_expr(&args[0])?;
|
||||
Ok(format!(
|
||||
"[...{}].sort((a, b) => a < b ? -1 : a > b ? 1 : 0)",
|
||||
list
|
||||
))
|
||||
}
|
||||
"sortBy" => {
|
||||
let list = self.emit_expr(&args[0])?;
|
||||
let func = self.emit_expr(&args[1])?;
|
||||
Ok(format!("[...{}].sort({})", list, func))
|
||||
}
|
||||
_ => Err(JsGenError {
|
||||
message: format!("Unknown List operation: {}", operation),
|
||||
span: None,
|
||||
|
||||
Reference in New Issue
Block a user