Skip to main content
added 11 characters in body
Source Link
Faly
  • 13.4k
  • 2
  • 21
  • 39

You sort your array by:

var arr = [['He', 2], ['saw', 1], ['her', 2], ['walking', 1], ['so', 1], ['asked', 1]]; function sortText(arr, wor) { arr.sort(([str1, nb1], [str2, nb2]) => wor ? (str1 > str2 ? 1 : -1) : nb1 - nb2) } sortText(arr, true) console.log(arr); sortText(arr, false); console.log(arr);

You sort your array by:

var arr = [['He', 2], ['saw', 1], ['her', 2], ['walking', 1], ['so', 1], ['asked', 1]]; function sortText(arr, wor) { arr.sort(([str1, nb1], [str2, nb2]) => wor ? str1 > str2 : nb1 - nb2) } sortText(arr, true) console.log(arr); sortText(arr, false); console.log(arr);

You sort your array by:

var arr = [['He', 2], ['saw', 1], ['her', 2], ['walking', 1], ['so', 1], ['asked', 1]]; function sortText(arr, wor) { arr.sort(([str1, nb1], [str2, nb2]) => wor ? (str1 > str2 ? 1 : -1) : nb1 - nb2) } sortText(arr, true) console.log(arr); sortText(arr, false); console.log(arr);

Source Link
Faly
  • 13.4k
  • 2
  • 21
  • 39

You sort your array by:

var arr = [['He', 2], ['saw', 1], ['her', 2], ['walking', 1], ['so', 1], ['asked', 1]]; function sortText(arr, wor) { arr.sort(([str1, nb1], [str2, nb2]) => wor ? str1 > str2 : nb1 - nb2) } sortText(arr, true) console.log(arr); sortText(arr, false); console.log(arr);