Algorithm API

You can add/edit your own javascript algorithm by clicking the "Add Algorithm" button at the bottom-left side of the main page.

When writing your algorithm, you have access to the AS (Audio Sort) global object. The methods on that object are described in the table below. The AS object gives you access to the current array, allows you to set visualization markers, and lets you "play" certain array elements.

Method Description Marker Color Marker Level
AS.length() Gets the length of the array. N/A N/A
AS.size() Gets the length of the array. N/A N/A
AS.get(index) Gets the sortItem object with the given array index. This sortItem can be passed to other AS method calls. N/A N/A
AS.play(item1, ..., itemN) Will play the given items. Items can be indexes or array items returned via AS.get() calls. N/A N/A
AS.mark(item1, ..., itemN) Will mark the given items. Items can be indexes or array items returned via AS.get() calls.
 
1
AS.lt(itemOne, itemTwo) Returns true if itemOne is less than itemTwo. Item can be an array index, or an array item (returned via an AS.get() call).
 
2
AS.lte(itemOne, itemTwo) Returns true if itemOne is less than or equal to itemTwo. Item can be an array index, or an array item (returned via an AS.get() call).
 
2
AS.gt(itemOne, itemTwo) Returns true if itemOne is greater than itemTwo. Item can be an array index, or an array item (returned via an AS.get() call).
 
2
AS.gte(itemOne, itemTwo) Returns true if itemOne is greater than or equal to itemTwo. Item can be an array index, or an array item (returned via an AS.get() call).
 
2
AS.eq(itemOne, itemTwo) Returns true if itemOne is equal to itemTwo. Item can be an array index, or an array item (returned via an AS.get() call).
 
2
AS.neq(itemOne, itemTwo) Returns true if itemOne is not equal to itemTwo. Item can be an array index, or an array item (returned via an AS.get() call).
 
2
AS.swap(itemOne, itemTwo) Will swap the positions of the two items.
 
3
N/A Items that were swapped in the last iteration, will show up below the "swapped" items. They appear as green circles, while items that are getting ready to be swapped show up as yellow circles.
 
4
AS.highlight(item1, ..., itemN) Will highlight the given items. Highlighted items stay highlighted until the next AS.highlight() call, or until AS.clearHighlight() is called.
 
5
AS.clearHighlight() Clears the currently highlighted items. N/A N/A