-
-
Save thinca/338845 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! s:uniq(list) "{{{ | |
let s:dict = {} | |
let counter = 1 | |
for i in a:list | |
if !has_key(s:dict, i) | |
let s:dict[i] = counter | |
let counter += 1 | |
endif | |
endfor | |
function! s:cmp(a, b) | |
return a:a == a:b ? 0 : a:a > a:b ? 1 : -1 | |
endfunction | |
function! s:c(a, b) | |
let [a, b] = [a:a, a:b] | |
return eval(s:expr) | |
endfunction | |
try | |
let s:expr = 's:cmp(s:dict[a], s:dict[b])' | |
return sort(keys(s:dict), 's:c') | |
finally | |
delfunc s:cmp | |
delfunc s:c | |
unlet s:expr | |
unlet s:dict | |
endtry | |
endfunction "}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment