SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict'
  2.  
  3. const f = (a, b) => {
  4.   return (a < b);
  5. }
  6.  
  7. const sortArr = (arr, f) => {
  8.   let sorted = [];
  9.   for (let i = 0; i < arr.length; i ++) {
  10.     let min = i;
  11.     for (let j = i + 1; j < arr.length; j++) {
  12.       if (f(arr[j], arr[min]))
  13.         min = j;
  14.     }
  15.     sorted.push(arr[min]);
  16.     arr[min] = arr[i];
  17.   }
  18.   return sorted;
  19. }
  20.  
  21. let arr = [12, 3, 4, 6, 123, 2, 0];
  22. let new_arr = sortArr(arr, f);
  23. console.log(new_arr);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top