-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The order of the functions in play editor is not the same as in the source code #21
Comments
|
Grouping the functions on type is useful, and then you could sort them alphabetically. |
Suggestion for a solution: var mf=
[
{name: "v3", type: "function", stateMutability: "view"},
{name: "v1", type: "function", stateMutability: "view"},
{name: "p3", type: "function", stateMutability: "pure"},
{name: "p2", type: "function", stateMutability: "pure"},
{name: "v4", type: "function", stateMutability: "view"},
{name: "p1", type: "function", stateMutability: "pure"},
{name: "p4", type: "function", stateMutability: "pure"},
{name: "v2", type: "function", stateMutability: "view"}
]
function type2num ({ stateMutability: sm }) {
if (sm === 'view') return 1
if (sm === 'nonpayable') return 2
if (sm === 'pure') return 3
if (sm === 'payable') return 4
if (sm === undefined) return 5
}
function sort (functions) {
return functions.filter(x => x.type === 'function').sort((a, b) => {
var d=type2num(a) - type2num(b)
if (d==0)
{
if (a.name > b.name) return 1;
if (a.name < b.name) return -1;
}
return d;
}
)
}
var sorted = sort(mf)
console.log(sorted); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The order of the functions in play editor is not the same as in the source code.
For example this source code:
Gives this output:
The text was updated successfully, but these errors were encountered: