xxxxxxxxxx
$ npm i -g create-react-native-app
$ create-react-native-app my-project
$ cd my-project
$ npm start
xxxxxxxxxx
// the most comman way of starting a react native app is,
npx create-expo-app YourApp
// as of 6th july 2023 it has many deprecated dependencies
// run
npm audit
//if it shows any vulnerability consider using
npx create-react-native-app YourApp
// and selecting expo template
xxxxxxxxxx
function swap(arr, leftIndex, rightIndex){
// swap 2 elements in the array
var temp = arr[leftIndex];
arr[leftIndex] = arr[rightIndex];
arr[rightIndex] = temp;
}
function partition(arr, left, right) {
var pivot = arr[Math.floor((right + left) / 2)], //middle element
i = left, //left pointer
j = right; //right pointer
while (i <= j) { // while left pointer is smaller than right pointer
while (arr[i] < pivot) { // move the left pointer to the right
i++;
}
while (arr[j] > pivot) { // move the right pointer to the left
j--;
}
if (i <= j) { //left pointer smaller or equal to right pointer
swap(arr, i, j); //sawpping two elements
i++;
j--;
}
}
return i;
}
// run as quickSort(array, 0, array.length - 1);
function quickSort(arr, left, right) {
var index;
if (arr.length > 1) {
index = partition(arr, left, right); //index returned from partition
if (left < index - 1) { //more elements on the left side of the pivot
quickSort(arr, left, index - 1);
}
if (index < right) { //more elements on the right side of the pivot
quickSort(arr, index, right);
}
}
return arr;
}
xxxxxxxxxx
#https://github.com/paulnegz/sorts-py/blob/main/sort.py
def quick_sort(array :list)->list:
def _quick_sort(array :list)->list:
if len(array)<=1: return array
pivot, is_bigger = array.pop(), lambda x: x>pivot
left_partition = _quick_sort([x for x in array if not is_bigger(x)])
right_partition = _quick_sort([x for x in array if is_bigger(x)])
return [*left_partition, pivot, *right_partition]
return _quick_sort(array)
arr = [7, 2, 4, 0, 1, 5, 8, 3, 2, 0]
print(quick_sort(arr)) # [0, 0, 1, 2, 2, 3, 4, 5, 7, 8]