Array.sort() is not available when programming Motoko

try to sort Array by using method Array.sort(), but build met error as:

type error [M0072], field sort does not exist in type

module {
append :
([A], [A]) → [A];
chain : <A, B>([A], A → [B]) → [B];
equal :
([A], [A], (A, A) → Bool) → Bool;
filter :
([A], A → Bool) → [A];
find :
([A], A → Bool) → ?A;
flatten :
([[A]]) → [A];
foldLeft : <A, B>([A], B, (B, A) → B) → B;
foldRight : <A, B>([A], B, (A, B) → B) → B;
freeze :
([var A]) → [A];
init :
(Nat, A) → [var A];
keys :
([A]) → Iter;
make :
(A) → [A];
map : <A, B>([A], A → B) → [B];
mapEntries : <A, B>([A], (A, Nat) → B) → [B];
mapFilter : <A, B>([A], A → ?B) → [B];
mapResult : <A, R, E>([A], A → Result<R, E>) → Result<[R], E>;
tabulate :
(Nat, Nat → A) → [A];
tabulateVar :
(Nat, Nat → A) → [var A];
thaw :
([A]) → [var A];
vals :
([A]) → Iter:
}

seems sort() is not a function for array, but it is mentioned in motoko library

as: Array :: Internet Computer

Crazy, I cam across this exact same thing a day ago… I ended up just copying the sort and sortInPlace functions from the motoko array lib on gibthub and it works for the time being.

That is… really odd. I created an issue, we’ll investigate.

1 Like

What is your dfx version? Until recently (and perhaps still), dfx was shipping an outdated moc 0.6.1 and base library.

LOL that works. :laughing:
would u mind to paste the code here…

my dfx version is 0.7.2

0.7.2 was still shipping Motoko 0.6.1.

Either stick with your workaround or, if you are feeling brave, try dfx 0.7.6.

Dfx 0.7.7 is now out, fixing issues with. 0.7.6.

1 Like