Home  >  Article  >  Web Front-end  >  Comparison of javascript and Python quick sort examples_javascript skills

Comparison of javascript and Python quick sort examples_javascript skills

WBOY
WBOYOriginal
2016-05-16 15:46:122641browse

The example in this article compares the implementation methods of JavaScript and Python quick sorting. Share it with everyone for your reference. The details are as follows:

js implementation method:

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]})))
}

Python implementation method:

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]])

I hope this article will be helpful to everyone’s javascript and Python programming.

Statement:
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