Questions tagged [sorting]

Sorting involves the systematic arrangement of a group of elements to establish a specific order.

arranging data in html table columns using angular 2

I am facing a challenge where I require each column of a table to be sorted in ascending order every time it is clicked. The sorting logic implemented is a standard JavaScript method. While this method works well in most scenarios, it encounters issues whe ...

JavaScript tool for implementing sorting features on an HTML table

I am facing an issue with my AJAX-loaded table where I need sorting functionality implemented. Despite searching for various JavaScript plugins, none seem to work efficiently due to slow performance or errors. The structure of my HTML table is unique with ...

Troubleshooting problem with sorting dates in MVC jQuery datatable

I have successfully implemented a datatable in MVC3 using c#. Everything was working perfectly on my local development machine, including the sorting of DateTime columns. However, when I uploaded the code to the server and accessed the webpage, I encounte ...

JavaScript Simplified Data Sorting after Reduction

I have extracted data from a JSON file and successfully condensed it to show the number of occurrences. Now, my next step is to arrange these occurrences in descending order, starting with the most frequent. To illustrate: var myData = [{ "datapo ...

Can someone guide me on how to organize a div structure into a table format with the help of JQuery

I am new to JQuery and I have created a table using divs instead of the traditional table structure. Each row has the same ids, which I thought would help me sort the table. Here's an example of my code: <div class="column_title">Column 1</div&g ...

What is the best method for shifting the values in an array to the 3rd position from the

Can the position of values in the array be changed? I currently have an array structured like this: [files] => Array ( [name] => Array ( [0] => file 1 [1] => file 2 [2] ...

What would be the most optimal choice for sorting in this particular situation within my PHP script?

I have successfully written a PHP script that can extract specific movie titles and ratings from a large file. However, I now need to modify the script to sort the movie titles with 'XXX' at the bottom of the list. I've considered using usort, but I'm unsu ...

Tips for arranging a secondary list according to the order of the first list?

Struggling to sort an ordered list based on the order of an unordered list? I attempted to do so by manipulating the indexes of each element in both lists without success. If anyone has faced a similar challenge or knows the right function to use, I'd appr ...

Python tutorial: utilizing the join() and sort() methods

My goal is to take an input string and produce a list of unique lowercase letters from that string, sorted in alphabetical order without any punctuation marks. For instance, if the input is "happy!", the output should be ['a','h','p','y']. I attempted to ...

Ways to arrange a 2d numpy array based on the elements within the subarrays?

Is there a way to sort an array of arrays based on the values of their elements using numpy without resorting to structured arrays? I want to sort the inner arrays first by the value of the first element, then the third element, and finally the second elem ...

Arrange a JSON response in descending order and filter out specific values

Currently, I'm encountering a challenge when trying to extract a specific attribute from my JSON response. The issue arises when I attempt to sort the results based on the `percentage_match` in descending order. Once sorted, my goal is to create an array ...

What is the best way to organize objects based on their timestamps?

I am faced with the task of merging two arrays of objects into a single array based on their timestamps. One array contains exact second timestamps, while the other consists of hourly ranges. My goal is to incorporate the 'humidity' values from t ...

Mix up and divide alike phrases

I want to rearrange emails based on domains in order to maximize the distance between them. For example: Original array: [email protected], [email protected], [email protected], [email protected], [email protected], [email ...

Sorting an array of objects in Typescript using a dynamic property name for generics

My goal is to develop a versatile, typed function that can arrange an array of objects by a numerical value housed under a dynamically named property within each object. Here is my current progress: export const sortByNumber = <T, K extends keyof T> ...

What is the best way to arrange the keys of a JavaScript object in a customized

I am struggling to find a way to custom sort a JavaScript object properly. For example, I have the following object: var test = { 'yellow': [], 'green': [], 'red': [], 'blue': [] } And an array with values like: var arr = ['red', 'green', 'blue', ...

Divergent Results in Sorting Algorithms Between Python Arrays and Numpy Arrays

Below, you will find some code for a merge sort algorithm that I have implemented. Initially, I tested it using a Python array of integers and everything was working perfectly. However, when I decided to test it further by generating a random set of number ...

Javascript datatables do not allow for setting a default column sort

I am encountering an issue where I need to sort the results by a specific column on page load. In this case, I want the initial results to be displayed in descending order based on "RecordDate". However, it seems that the server side is blocking any sort ...

Retrieving a specific item using its ID from a JSON file with Ionic 5

Newcomer's query For multiple Ionic pages, I require fetching a specific item by ID from a centralized JSON file. The structure of my JSON data is as follows: { "items": [ { "id":"0", "link&q ...

Methods for organizing an array of objects by a specific key in JavaScript, but in the case of duplicate values, the objects can be sorted by a different

I'm struggling to sort an array of objects by two different keys. I need to first sort the array by price, and if there are multiple items with the same price, they should then be sorted by time. Here's what my array looks like: var myArr = [ {&q ...

When using TypeScript, my sorting function returns a value of 0 for all time values

I have been trying to sort this JSON data by date using the provided code, but it does not seem to work as expected. Below is a snippet of my JSON: { "StatusCode":0, "StatusMessage":"OK", "StatusDescription":[ { "id":"1", ...

What is the procedure for utilizing the comparator to arrange items according to various attributes?

I am trying to find a way to arrange my models in a collection based on their required flag and then alphabetically by their value. This is what my current code looks like: var myModel = Backbone.Model.extend({ defaults: { required: true, ...

Arranging elements within an outer array by the contents of their inner arrays

I need help organizing an array based on the alphabetical order of a specific value within the inner arrays. For example: I want to sort this array by the prefix "old," so old A, old B, etc. const array = [ { personName: "Vans", personTags: ["young", " ...

Sorting of alphanumeric columns may not always be accurate

I am encountering an issue with sorting a list of invoice numbers that consist of both letters and digits. Despite expecting Invoice no - 192685 to appear before Invoice no - 19s100619916001 when sorting in descending order, the actual result is the opposi ...

Variations in outcomes when sorting an Excel document with the help of pandas and the pywin32 API

I am seeking a way to organize the contents of an Excel file that includes the following data: 1.jpg CC Library - Screen for proxy.png aAd.ai aaa.PSD automation_35.jpg automation_36.jpg automation_37.jpg automation_371.jpg sad.psd sde-Recovered.ai sde-Rec ...

How to Reverse Text in a File with PHP

I have a document that is currently sorted in ascending order using natsort()... However, I need to reverse the order and have it sorted in descending order instead. This means that the last line of the document should now be the first line, and vice ver ...

What is the method for sorting a Python list both numerically in descending order and alphabetically in ascending order simultaneously?

My goal is to arrange a list that contains tuples with a word and a number. my_list = [('hello',25), ('hell',4), ('bell',4)] I am looking for a way to sort this list (maybe using lambda) in order to achieve the following: [ ...

arrange the array of dates in order and organize the sorted information

In my mongoose schema, I have defined two different models. The first model includes fields such as name, description, subcategory, price, and provider. The second model consists of fields like monto, fecha, idProvider, and idProduct. My goal is to retrie ...

Organize an array of objects with underscore.js to arrange them in a

I have an array of objects that looks like this: profData=[{"Details":{"CODE":"PAT4PAS","DESCRIPTION":"PASTIE 4N20 12 X 175G","LOCATION":"FREEZER","UNITS":"BOX","WAREHOUSE":"00","AVAILABLE":"15.0000","ON_HAND":"15.0000","BRAND":"4N20","PRICE1":"18.80"," ...

Rearrange HTML list items automatically according to changes in numeric sort order

I am working on a web page that features a dynamic ranked list. The items in the list are assigned a specific rank order number which changes based on user interactions elsewhere on the page. I have been exploring different options to automatically reorgan ...

Sorting arrays of objects with multiple properties in Typescript

When it comes to sorting an array with objects that have multiple properties, it can sometimes get tricky. I have objects with a 'name' string and a 'mandatory' boolean. My goal is to first sort the objects based on age, then by name. But how can this be ...

Ordering an Array of JavaScript Objects in a Custom Sequence (utilizing pre-existing methods)

Imagine we have an array of objects: ["c", "a", "b", "d"] Is there a way in ECMAScript or through a third-party JavaScript library to rearrange the objects in the first array to match the order specified by the second array, all within one line or functi ...

Comparing Python's QuickSort Efficiency: List Comprehension versus Recursion (Partition Routine)

After watching the talk Three Beautiful Quicksorts, I decided to experiment with quicksort in Python. My initial implementation closely resembled C (selecting a pivot, partitioning around it, and recursing over smaller and larger partitions), which I felt ...

Transforming MATLAB script into Python

As a newcomer to Python, I am struggling with vectorized operations and indexing in Python. While I can easily rewrite it in C-style for element-by-element calculation, I want the Python code to be more "pythonic" and concise like MATLAB. I aim for brevity ...

Perform a filtering operation on the sorted array output and generate a fresh array

Yesterday, I had an issue sorting XML results into an associative array, but I managed to resolve it. (you can view my code here) <?php $xmlData = 'http://xml.betfred.com/Horse-Racing-Daily.xml'; $xml = simplexml ...

Sorting a React map function based on two fields

I am new to React and I am trying to sort an array by two different dates: {folder.actions .sort((a,b) => { return a.date_actual - b.date_actual || a.date_sched - b.date_sched }) .map(action => { ... However, the code above is not work ...

"Organizing Data with Angular 2's Sorting Pipe for Arrays of

Guide to Creating a Sorting Pipe in Angular 2 Using an Array of Objects Initial Challenge: I am working with a TODOs list (Todo[ ]), and I need to sort it every time modifications are made. The desired outcome is to have completed todos appear at the bot ...

Eliminate redundant items from the array

"name": [ { "name": "test1" }, { "name": "test2" }, { "name": "test3" }, { "name": "test1" }, ] Generated by a Node.js script, the structure ab ...

Guide to custom sorting and sub-sorting in AngularJS

If I have an array of objects like this: [ { name: 'test1', status: 'pending', date: 'Jan 17 2017 21:00:23' }, { name: 'test2', status: 'pending', date: 'Jan 1 ...

Sort the inner array within an outer array

const dataArray = [ { id: 1, title: "stuffed chicken is tasty as anything", picture: "./img/chicken.jpg", tags: ["oooo", "tasty", "stuffed"] }, { id: 2, title: "noodles with shrimp and salad", ...

Filtering tables with checkboxes using Next.js and TypeScript

I've recently delved into Typescript and encountered a roadblock. While I successfully tackled the issue in JavaScript, transitioning to Typescript has left me feeling lost. My dilemma revolves around fetching data from an API and populating a table using ...

How can strings of dates be arranged in MM/DD/YYYY order?

Is there a correct way to sort these dates in descending order? I've attempted using arr.sort() and arr.sort().reverse(), searched extensively on stack overflow, but still cannot find a solution. Every attempt at sorting them seems to be incorrect. [ ...

Are the sorting algorithms for BackboneJS and AngularJS considered stable sorting methods?

I'm considering incorporating BackboneJS and AngularJS into my app. However, I'm curious about the stability of sorting algorithms in these frameworks. Specifically, I would like to know if they maintain the order of previously sorted columns wit ...

Arranging an array of arrays based on the mm/dd/yyyy date field

Currently, I am facing an issue while attempting to sort data obtained from an API by date in the client-side view. Here is an example of the data being received: address: "1212 Test Ave" address2: "" checkNumber : "" city: "La Grange" country: "" email: ...

Looking to organize an array of objects containing two string elements (countries) based on the country name using TypeScript or the Lodash library?

Below is an example of an array of objects I am working with: { countries: [{ "country_alpha2_code": "PW", "country_name": "PALAU" },{ "country_alpha2_code": "US&qu ...

arranging an array of key-value pairs by a boolean attribute

The array $list is filled as follows: - $list[$i++] = array( "date" => $date, "desc" => $desc, "priority" => $priority ); If certain criteria are met, the variable $priority is set to TRUE. I want the rows in the $list to be sorted ...

What is the best way to categorize a collection of objects within a string based on their distinct properties?

I am working with an array of hundreds of objects in JavaScript, each object follows this structure : object1 = { objectClass : Car, parentClass : Vehicle, name : BMW } object2 = { objectClass : Bicycle, parentClass : Vehicle, name : Giant } object3 = { ob ...

Is it possible for me to customize the default angular filter in order to prioritize displaying strings that begin with the search term?

In my current project, we are dealing with a massive list of strings (17,000+ at times) and have implemented an input box for filtering the list. Initially, I used Angular's default filter, but then a request came in to sort the list so that strings starti ...

Arrange the elements of the array in alphabetical order and categorize them based on their initial letter

Is there a way to organize an array alphabetically and categorize it by the first letter in PHP? I am curious about how to achieve this using PHP. I have a list of names that I retrieve from the database. Specifically, I am interested in: https://i.sta ...

I'm wondering if there exists a method to arrange a multi-array in javascript, say with column 1 arranged in ascending order and column 2 arranged in descending order?

Here is an example of a randomly sorted multi-array: let arr = [[3, "C"], [2, "B"], [3, "Q"], [1, "A"], [2, "P"], [1, "O"]]; The goal is to sort it in the following order: arr = [[1, "O" ...

Arranging a JSON array based on the numerical value within an object

I am interested in sorting an array from a json file based on distances calculated using the haversine library. The purpose is to find geolocations near a specified value and display the closest results first. function map(position){ var obj, ...

Extracting integer values from strings within a DataFrame column containing colons

I have a DataFrame with the following data: C1 C2 A 2:3:1:7 B 2:1:4:3 C 2:1:1:1 My task is to sort the integers in column C2, while keeping the colons intact. The desired output should be as follows: C1 C2 A 1:2:3:7 B 1:2:3:4 C 1:1: ...

Using JavaScript to display a selection of objects from an array: showcasing x out of x items

What is the most efficient method for sorting or querying an array of objects using JavaScript? For example, how can I retrieve only the first two objects, followed by the next two, or obtain 5 objects starting from the 5th position? Which specific functi ...

Sorting for the best price in Java using Selenium

I am currently using selenium to automate the process on makemytrip.com. My main goal is to identify the lowest fare available in the list of options provided. Below is the code I am utilizing: List<WebElement> results = driver.findElements(By.xpa ...

Here's how you can arrange a list starting with the first item and then searching for a specific string using md-autocomplete in

As a newcomer to angularJs, I am looking for ways to filter search results more efficiently. Check out this example here: https://codepen.io/anon/pen/mpJyKm I am trying to customize the search result by filtering based on query input. Specifically, I wan ...

Sorting of dates in mui-datatables is not accurate

I have dates that are formatted using moment.js, for example ("Sat, Feb 22, 2020 12:55 PM") I retrieve them from firestore, and they appear to come in correctly as I first sort them in descending order. forms.sort(function(left, right) { return moment.u ...

What is the method for customizing the onHover text in the tableHead using material-ui?

I am trying to customize the onHover text in my table header created using material-ui's tableHead component. Currently, when I hover over the header it displays 'sort', but I want to translate this text and change it to something else. Howe ...

Switching the sorting criteria from 'AND' to 'OR' in the JPList library

I am currently exploring the use of JPList to sort on multiple items. As it stands, JPList searches like 'AND' when sorting (e.g. sorting based on an item with tags html, php and jQuery all together), but I am interested in filtering through all items that ...

"Handsontable organizes information pulled directly from the backend database using JSON/AJAX

In order to implement the Handsontable column sorting and direction indicators, I would like to create a mechanism that sends sort requests to my database and displays the corresponding results. Although the Handsontable sort plugin is effective in allowi ...

Order JSON object based on designated Array

I'm looking to organize a JSON object in a specific order, Here is the current object structure: { "you": 100, "me": 75, "foo": 116, "bar": 15 } I would like to rearrange this object in the following sequence ['me', 'foo', &apos ...

What is the method for extracting a list of properties from an array of objects, excluding any items that contain a particular value?

I have an array of objects, and I want to retrieve a list with a specific property from those objects. However, the values in the list should only include objects that have another property set to a certain value. To clarify, consider the following example ...

"I encountered an error while sorting lists in Vue 3 - the function this.lists.sort is not

Creating a Vue 3 front-end template: <template> <div class="container"> <router-link to="/user/create" class="btn btn-success mt-5 mb-5">Add New</router-link> <table class=" ...

PHP divide and organize

I am currently facing an issue with sorting an exploded string before writing it into a database. While the code provided below does work, I have encountered difficulty in determining the summary of arrays outside the foreach loop. Therefore, using $term ...

Arranging data using metadata in a Mongoose schema

I am currently developing an application that involves uploading images and displaying them as thumbnails side by side. My goal is to incorporate filtering options so users can view the images in a different order, such as arranging them based on the numbe ...

What are the steps to sorting in JavaScript?

I need help with sorting an array. The array I have looks like this: var temp = [{"rank":3,"name":"Xan"},{"rank":1,"name":"Man"},{"rank":2,"name":"Han"}] I've tried to sort it using the following code: temp.sort(function(a){ a.rank}) But unfortunately ...

Vue - Issue with DOM not updating after array sorting operation

I've been working on sorting some JSON data with Vue, and I've encountered an issue. Although the data changes when checked in the Vue console debugger, the DOM doesn't reflect these updates. Here's the Vue code I'm using: Array. ...

Organize complex data retrieved through mongoose filtering with a deep nesting, in a

I am currently using mongoose filter to extract nested data from a MongoDB document. I am looking for guidance on how to efficiently sort the results and if there are any better methods or resources available (Please suggest some solutions or references if ...

Struggling with Material-UI DataGrid's sorting issue in numeric columns

I am currently working on a project involving the DataGrid Component from Material-UI. While data can be displayed, I am encountering issues with the built-in sorting feature. When attempting to sort in ascending or descending order, it seems to be priorit ...

Delete Entries in MongoDB Collection According to Unique User Pairs

I have a collection of messages stored in MongoDB and I need to keep only the latest 500 records for each pair of users. Users are identified by their sentBy and sentTo attributes. /* 1 */ { "_id" : ObjectId("5f1c1b00c62e9b9aafbe1d6c&quo ...

tips for instructing the p-table to sort particular columns by utilizing a subfield

I currently have data structured with nested JSON as follows: users = [ { name: "ABC", age: 11, activity : { date: 11-Aug-2020, title: "some activity", loc: "so ...

What is causing my array of objects to constantly accumulate undefined elements?

My quick sort function implementation for the object users_total_likes is behaving unexpectedly. When compiled and run in the terminal or browser, it adds undefined values causing a TypeError: if(users[i][key] >= users[hi][key] && users[j][key] ...

Tips for organizing MySQL information based on group importance

I am currently working on sorting MySQL data using PHP based on priority grouping. In my database, I have a table named "users" which stores members' profile information and another table named "reviews" which contains feedback from members along with ...

Arrange the complex nested array or final JSON based on the key's name

I am currently in the process of sorting a rather large multidimensional array based on key names (and not values), while also aiming for the fastest possible solution. The resulting array will be converted to JSON and stored in a file, so if there is a m ...

Dividing the array into distinct subarray groups

I am working with a JavaScript array that contains strings, like this: let a = ["a", "a", "a", "b", "c", "c", "b", "b", "b", "d", "d", "e&quo ...

Tips for changing binary heap sort into d-ary heap sort:

Hey there! I have an algorithm that utilizes a binary tree for heapifying and sorting a list. I am looking to modify this sorting algorithm to work with a d-heap, d-ary heap, or k-ary heap structure instead. Here is my code: def build_heap(lista, num): ...

How can I use jQuery to reposition an inner element to the front?

Imagine you have a collection of elements: <ul id="ImportantNumbers"> <li id="one"></li> <li id="two"></li> <li id="topNumber"></li> <li id="four"></li> </ul> Every five seconds, the ...