sorting

Sorting an array which contains string, date and number

馋奶兔 提交于 2020-02-02 04:13:06
问题 var myArray = [ '_aaaa_2013-09-25_ssss9.txt', '_aaaa_2013-09-25_ssss8.txt', '_aaaa_2013-09-26_ssss1.txt', '_aaaa_2013-09-25_ssss10.txt', '_aaaa_2013-09-26_ssss2.txt', '_aaaa_2013-09-25_ssss13.txt', '_aaaa_2013-09-25_ssss5.txt', '_aaaa_2013-09-25_ssss6.txt', '_aaaa_2013-09-25_ssss7.txt' ]; I need to sort the array by date and number. Result should be var result = [ '_aaaa_2013-09-25_ssss5.txt', '_aaaa_2013-09-25_ssss6.txt', '_aaaa_2013-09-25_ssss7.txt', '_aaaa_2013-09-25_ssss8.txt', '_aaaa

Sorting date field in unix

房东的猫 提交于 2020-01-31 18:32:11
问题 I have text file which contains hundreds of thousands of records. One of the fields is a date field. Is there is any way to sort the file based on the date field? 09-APR-12 04.08.43.632279000 AM 19-MAR-12 03.53.38.189606000 PM 19-MAR-12 03.56.27.933365000 PM 19-MAR-12 04.00.13.387316000 PM 19-MAR-12 04.04.45.168361000 PM 19-MAR-12 03.54.32.595348000 PM 27-MAR-12 10.28.14.797580000 AM 28-MAR-12 12.28.02.652969000 AM 27-MAR-12 07.28.02.828746000 PM The Output should come as 19-MAR-12 03.53.38

sort by number of occurrence(count) in Javascript array

我是研究僧i 提交于 2020-01-31 05:44:13
问题 I am new to Jquery and Javascript. Can someone please help me with Jquery sorting based on number of occurrence(count) in array. I tried various sorting methods but none of them worked. I have an array in Javascript which is allTypesArray = ["4", "4","2", "2", "2", "6", "2", "6", "6"] // here 2 is printed four times, 6 is printed thrice, and 4 is printed twice I need output like this newTypesArray = ["2","6","4"] I tried function array_count_values(e) { var t = {}, n = "", r = ""; var i =

Sorting strings in descending order in Javascript (Most efficiently)?

亡梦爱人 提交于 2020-01-31 04:16:10
问题 W3CSchools has this example: var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.sort(); fruits.reverse(); Is this the most efficient way to sort strings in descending order in Javascript? Update One of the answers is using localeCompare . Just curious whether if we do reverse() , will that work for all locales (Maybe this is a separate question - Just let me know in the comments)? 回答1: If you consider obj.sort().reverse(); VS obj.sort((a, b) => (a > b ? -1 : 1)) VS obj.sort((a, b) =>

Sort a numpy array by another array, along a particular axis

◇◆丶佛笑我妖孽 提交于 2020-01-30 15:34:06
问题 Similar to this answer, I have a pair of 3D numpy arrays, a and b , and I want to sort the entries of b by the values of a . Unlike this answer, I want to sort only along one axis of the arrays. My naive reading of the numpy.argsort() documentation: Returns ------- index_array : ndarray, int Array of indices that sort `a` along the specified axis. In other words, ``a[index_array]`` yields a sorted `a`. led me to believe that I could do my sort with the following code: import numpy a = numpy

django order_by query set, ascending and descending

你。 提交于 2020-01-30 13:45:26
问题 How can I order by descending my query set in django by date? Reserved.objects.all().filter(client=client_id).order_by('check_in') I just want to filter from descending all the Reserved by check_in date. 回答1: Reserved.objects.filter(client=client_id).order_by('-check_in') Notice the - before check_in . Django Documentation 回答2: Reserved.objects.filter(client=client_id).order_by('-check_in') A hyphen "-" in front of "check_in" indicates descending order. Ascending order is implied. We don't

Collections.sort() Comparison method violates its general contract in Java [duplicate]

Deadly 提交于 2020-01-30 13:17:10
问题 This question already has answers here : “Comparison method violates its general contract!” (11 answers) Closed 2 years ago . I know that this kind of question has been asked millions of times if not billions, however I couldn't find my answer yet :) This compare() method doesn't have Long , Double , Float , ..., it only has Date , boolean , and Null checker, however it shows me that contract violation error , can any one help plz? Collections.sort(users, new Comparator<MiniUser>() {

Collections.sort() Comparison method violates its general contract in Java [duplicate]

社会主义新天地 提交于 2020-01-30 13:17:07
问题 This question already has answers here : “Comparison method violates its general contract!” (11 answers) Closed 2 years ago . I know that this kind of question has been asked millions of times if not billions, however I couldn't find my answer yet :) This compare() method doesn't have Long , Double , Float , ..., it only has Date , boolean , and Null checker, however it shows me that contract violation error , can any one help plz? Collections.sort(users, new Comparator<MiniUser>() {

Python: Sort list by date?

社会主义新天地 提交于 2020-01-30 13:15:34
问题 Is it possible to sort this list by date? It is for a flot graph so it has to be organized in this format of a list of smaller list pairs. I would like to be able to sort it by date. [["2014-5-29", 19], ["2014-5-28", 16], ["2014-5-30", 20], ["2014-5-23", 16], ["2014-5-22", 1225], ["2014-5-21", 114], ["2014-5-20", 69], ["2014-5-27", 10], ["2014-5-31", 17], ["2014-5-25", 18], ["2014-5-24", 19], ["2014-5-26", 18], ["2014-6-2", 19], ["2014-6-1", 19], ["2014-5-18", 4], ["2014-5-19", 27]] Thanks!

Sort nested array of object in javascript

大兔子大兔子 提交于 2020-01-30 12:18:04
问题 let arr = [{ name: 'Apple', trades: [{ date: '2017.01.01', volume: 100 }, { date: '1995.02.01', volume: 150 }, { date: '2008.01.01', volume: 250 }] }] Hello, I googled many documents for sorting nested object in JavaScript, but I couldn't find the way of my case and I struggled so many hours so I want to ask to how can I sort above array of objects. What I expected result is sort array of object by trades.date like this sortedArray = [{ name: 'Apple', trades: [{ date: '2017.01.01', volume: