길이 순 정렬

1 PHP[ | ]

$a = ['world','el','h','llo'];
array_multisort(array_map('strlen',$a), $a);
print_r( $a );
# Array
# (
#     [0] => h
#     [1] => el
#     [2] => llo
#     [3] => world
# )

2 Python[ | ]

a = ['world','el','h','llo']
print( sorted(a, key=len) )
# ['h', 'el', 'llo', 'world']

3 R[ | ]

v <- c('world','el','h','llo')
v[order(nchar(v), v)]
## [1] "h"     "el"    "llo"   "world"

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}