我想在单击按钮时对参数进行排序:id,薪水和年龄。假设我必须动态清理我的表(deleteRow),进行排序,然后再次显示数据。但是,似乎很难。有人可以帮我吗?有没有更好的办法?
JavaScript:
const butt = document.getElementById('button');
const swTable = document.getElementById('table').getElementsByTagName('tbody')[0];
const url = 'http://dummy.restapiexample.com/api/v1/employees';
function fetchFromUrl(url) {
return fetch(url).then(function(resp) {
return resp.json()
});
}
function createElement(nameOfTag, text) {
const element = document.createElement(nameOfTag);
const content = document.createTextNode(text);
element.appendChild(content);
return element;
}
function createTable(data) {
const table = document.createElement('tr');
const {
id,
employee_name,
employee_salary,
employee_age
} = data;
table.appendChild(createElement('td', id))
table.appendChild(createElement('td', employee_name))
table.appendChild(createElement('td', employee_salary))
table.appendChild(createElement('td', employee_age))
return table;
}
fetchFromUrl('http://dummy.restapiexample.com/api/v1/employees')
.then(data => {
data.forEach(result => {
const row = createTable(result);
swTable.appendChild(row);
}) …Run Code Online (Sandbox Code Playgroud)我正在按升序和降序对数组进行排序。我做了两种方法,从main调用了它们。这些方法可以单独很好地工作,但是当我同时调用它们时,似乎最后一个覆盖了第一个的值。我知道应该很容易,但是我不知道发生了什么。有人可以向我解释吗?
import java.lang.reflect.Array;
public class Test {
public static void main(String[] args) {
int[] mayor, menor;
int[] array1 = new int[] {5,3,10,8,27,4,1 };
mayor= ordenMayor(array1);
menor= ordenMenor(array1);
for(int i=0; i<mayor.length ;i++) {
System.out.print(" "+mayor[i]+" ");
}
System.out.println("");
for(int i=0; i<menor.length ;i++) {
System.out.print(" "+menor[i]+" ");
}
System.out.println("");
for(int i=0; i<array1.length ;i++) {
System.out.print(" "+array1[i]+" ");
}
}
public static int[] ordenMayor(int[] arrayM) {
int[] arrayMayor=arrayM;
int mayor;
int index;
for(int i=0; i<arrayMayor.length - 1;i++) {
mayor=arrayMayor[i];
index=i;
for(int j=i; j<arrayMayor.length …Run Code Online (Sandbox Code Playgroud) 我有一个包含数千行的数据框。数据帧由带有数值的列排序。我想创建一列,指示该行是否为包含特定数值的第一行。它应该仅基于该列。
数据框A是当前如何组织数据的示例,数据框B是我希望如何组织数据的示例。
A <- data.frame(c(22, 27, 32, 32, 33, 33, 37), c(121, 243, 765, 322, 433, 435, 728))
colnames(A) <- c("V1", "V2")
B <- data.frame(c(22, 27, 32, 32, 33, 33, 37), c(121, 243, 765, 322, 433, 435, 728), c("y", "y", "y", "n", "y", "n", "y"))
colnames(B) <- c("V1", "V2", "V3")
Run Code Online (Sandbox Code Playgroud) 我试图以ArrayList<Person>相反的顺序对此进行排序,但这无法编译
List<Person> newList = arrayList.stream()
.sorted(Comparator.reverseOrder(Person::getAge)) //Error
.limit(3)
.collect(Collectors.toList());
newList.forEach(System.out::println);
Run Code Online (Sandbox Code Playgroud)
还有其他方法可以对流进行反向排序吗?
我又来了。我在尝试对c中的结构数组进行排序时遇到问题,我知道我的代码不够好,但是请不要对我不礼貌!
我尝试更改函数参数,但我已经筋疲力尽了,我敢肯定,如果我继续的话,我会做更多的错误,所以我需要您的帮助。
这是我程序的完整代码 https://pastebin.com/p28EbY8i
// I've 2 struct
typedef struct{ // Not used in this function
int id;
char * nome;
char * presidente;
char * allenatore;
} squadra;
typedef struct{ // I've an array of this type of data
int id;
char * nome;
char * cognome;
int eta;
char * ruolo;
squadra team;
char * college;
int td;
} giocatore;
// This is what i wrote for my function
size_t ordina_classifica(size_t sz, giocatore array[]){ //sz is the array …Run Code Online (Sandbox Code Playgroud) 在工作中,我们最近升级到了熊猫0.20,我有一个使用sort排序的数字列表(但是不再支持,尝试时会收到上述消息sort_values)。
numbers = [1, 3, 4, 2]
numbers.sort(reverse = True)
print numbers
[4, 3, 2, 1]
numbers.sort_values(reverse = True)
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
追溯(最近一次通话):
文件“”,第1行,位于
AttributeError:“列表”对象没有属性“ sort_values”
我有一个重要性数组,我想按重要性排序,如下所示:
let criticalityTypes = ['CRITICALITY_LOW', 'CRITICALITY_HIGH', 'CRITICALITY_MEDIUM'];
Run Code Online (Sandbox Code Playgroud)
我会随机获得此顺序,有时** CRITICALITY_LOW **出现在矩阵的位置1,即位置2或“ CRITICALITY_MEDIUM”位于0位置,
我想做的是按照以下顺序进行排序,而不管我遇到的顺序如何,有时我只有一个或两个临界值:
['CRITICALITY_HIGH', 'CRITICALITY_MEDIUM', 'CRITICALITY_LOW'];
Run Code Online (Sandbox Code Playgroud)
我试图使用排序功能来排序到目前为止我所做的是:
return criticalityTypes.sort((a, b) => {
if (a < b) return -1;
if (a > b) return 1;
});
Run Code Online (Sandbox Code Playgroud)
但是没有成功,有什么帮助吗?
Perl Sort函数无法以预期的增量方式排列数组元素
@array_sort = sort { $a <=> $b } @array
@array = ("BE_10", "BE_110", "BE_111", "BE_23", "BE_34", "BE_220", "BE_335");
@array_sort = sort { $a <=> $b } @array;
print "array_sort = @array_sort\n";
Run Code Online (Sandbox Code Playgroud)
预期结果:array_sort =
BE_10 BE_23 BE_34 BE_110 BE_111 BE_220 BE_335实际结果:array_sort =
BE_10 BE_110 BE_111 BE_23 BE_34 BE_220 BE_335
我想基于子列表中第二项的长度对列表列表进行排序,如下所示:
输入:
list = [['A', '1234', 'X'],['B', '12', 'X'],['C', '12345', 'X'],['D', '123', 'X']]
Run Code Online (Sandbox Code Playgroud)
输出:
list = [['C', '12345', 'X'],['A', '1234', 'X'],['D', '123', 'X'],['B', '12', 'X']]
Run Code Online (Sandbox Code Playgroud)
到目前为止,我有:
list = sorted(list, key=len, reverse=True)
Run Code Online (Sandbox Code Playgroud)
但是我不确定如何让它查看列表中特定项目的长度。提前致谢!
我需要获取时间戳记文件夹中的文件路径(以秒为单位)。文件夹名称示例0.000989965428461和1.00189731936e-05
而且我也需要写出时间。
我尝试了一些变体,key=以list.sort(key='')获得从坏到坏的不同结果。我缺乏对潜在问题的list.sort()理解:“理解”我的字符串是数字,但不理解x.xxe-xx也是数字格式。
我必须获取路径文件并将时间写为csv
#### import the simple module from the paraview
from paraview.simple import *
import os
import csv
import re
param='mitteQuer0'
fieldOne= 'U_zCut.vtk'
fieldTwo= 'p_rgh_zCut.vtk'
fieldThree= 'alpha.water_zCut.vtk'
fieldOneVTKs= []
fieldTwoVTKs=[]
fieldThreeVTKs=[]
time=[]
steps=[]
timeNsteps=[]
#Get path of the script
dir_path = os.path.dirname(os.path.realpath(__file__))
#Make folder path
path = dir_path + '/postProcessing/'+param
for path, dirs, files in os.walk(path, topdown=False):
dirs.sort()
for name in dirs:
fieldOneVTKs.append(os.path.join(path, name+'/'+fieldOne))
fieldTwoVTKs.append(os.path.join(path, name+'/'+fieldTwo))
fieldThreeVTKs.append(os.path.join(path, name+'/'+fieldThree))
with …Run Code Online (Sandbox Code Playgroud)