Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

sort array

Array.Sort(array); // this will Modify original Array
Comment

ordering array

var numbers = [4, 2, 5, 1, 3];
numbers.sort(function(a, b) {
  return a - b;
});
console.log(numbers);

// [1, 2, 3, 4, 5]
Comment

sort array

a = ['12', '24', '44', '32', '55'] 
a.sort! # a is now sorted 
 
a.sort # returns a sorted array, but does not modify a itself. Typical use: b = a.sort
Comment

sort array

let sortArray =  array.sorted(by: { $0.name.lowercased() < $1.name.lowercased() })
Comment

sort array

go mod edit -go=1.18
Comment

sorting array

       int current = 0;
        for (int i = 0; i < array.length ; i++) {
            for (int j = i+1; j < array.length ; j++) {
                if (array[i]>array[j]) {
                    current = array[i];
                    array[i] = array[j];
                    array[j] = current;
                }
            }
        }
Comment

sort array

//The sort() method sorts an array alphabetically:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.sort();
//output >> [ "Apple",Banana","Mango", "Orange" ]

//if you find the answer is useful ,
//upvote ⇑⇑ , so can the others benefit also . @mohammad alshraideh ( ͡~ ͜ʖ ͡°)
Comment

sort an array

// C++ code for k largest elements in an array
#include <bits/stdc++.h>
using namespace std;
  
void kLargest(int arr[], int n, int k)
{
    // Sort the given array arr in reverse
    // order.
    sort(arr, arr + n, greater<int>());
  
    // Print the first kth largest elements
    for (int i = 0; i < k; i++)
        cout << arr[i] << " ";
}
  
// driver program
int main()
{
    int arr[] = { 1, 23, 12, 9, 30, 2, 50 };
    int n = sizeof(arr) / sizeof(arr[0]);
    int k = 3;
    kLargest(arr, n, k);
}
  
// This article is contributed by Chhavi
Comment

PREVIOUS NEXT
Code Example
Javascript :: js alert new line 
Javascript :: react router active link css 
Javascript :: await is only valid in async function 
Javascript :: constant values javascript 
Javascript :: lodash update object by id in array 
Javascript :: setinterval javascript 
Javascript :: jquery ui dialog position fixed center 
Javascript :: display image on button click javascript 
Javascript :: js get index of item in array 
Javascript :: javaScript getHours() Method 
Javascript :: javascript array filter duplicates in react 
Javascript :: usecontext react 
Javascript :: detect adblock javascript 
Javascript :: Error: contextBridge API can only be used when contextIsolation is enabled 
Javascript :: moment set time 
Javascript :: js comparison operators 
Javascript :: js remove key from object 
Javascript :: select selectedindex jquery 
Javascript :: print first n prime numbers in javascript 
Javascript :: save console log to file nodejs 
Javascript :: placeholder text disappear when click in react 
Javascript :: json comments 
Javascript :: check user login or not in Shopify 
Javascript :: new map js 
Javascript :: nmapscript location 
Javascript :: mongoose updateone example 
Javascript :: electron get printer list 
Javascript :: nodejs http get request to external server 
Javascript :: javascriot function 
Javascript :: cors problem node js 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =