We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2a4808f commit 82f57f4Copy full SHA for 82f57f4
src/javascript/lib/core/erlang_compat/lists.js
@@ -220,6 +220,26 @@ function splitwith(pred, list) {
220
return new ErlangTypes.Tuple(list1, list2);
221
}
222
223
+function sort(...args) {
224
+ if (args.length === 1) {
225
+ const list2 = [...args[0]];
226
+ return list2.sort();
227
+ }
228
+
229
+ const fun = args[0];
230
+ const list2 = [...args[1]];
231
232
+ return list2.sort((a, b) => {
233
+ const result = fun(a, b);
234
235
+ if (result === true) {
236
+ return -1;
237
238
239
+ return 1;
240
+ });
241
+}
242
243
export default {
244
reverse,
245
foreach,
@@ -243,4 +263,5 @@ export default {
263
all,
264
any,
265
splitwith,
266
+ sort,
246
267
};
0 commit comments