Home > Web Front-end > JS Tutorial > body text

Comparing javascript vs Python quick sort

巴扎黑
Release: 2017-09-14 12:01:08
Original
1282 people have browsed it

本文实例对比了javascript与Python快速排序实现方法。分享给大家供大家参考。具体如下:

js实现方法:

function quicksort(arr) {
 if (arr.length <= 1) return arr
 return quicksort(arr.filter(function (lt, i) {return i > 0 && lt < arr[0]}))
    .concat([arr[0]])
    .concat(quicksort(arr.filter(function(ge, i) {return i > 0 && ge >= arr[0]})))
}
Copy after login

python实现方法:

def quicksort(arr):
 if len(arr) <= 1: return arr
 return quicksort([lt for lt in arr[1:] if lt < arr[0]]) + a[0:1] + 
  quicksort([ge for ge in arr[1:] if ge >= arr[0]])
Copy after login

The above is the detailed content of Comparing javascript vs Python quick sort. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template