Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 views
in Technique[技术] by (71.8m points)

javascript - 将下划线sortBy转换为Javascript(Convert underscore sortBy to javasscript)

I have an array which was sorted using Underscore's array function _.sortBy() , which I need to convert it into a vanilla JS function .sort() .(我有一个使用_.sortBy()的数组函数_.sortBy()排序的数组,我需要将其转换为普通的JS函数.sort() 。)

My problem is when I convert it to normal vanilla array.sort() function, my IDE (Webstorm) is throwing an error as:(我的问题是,当我将其转换为普通的vanilla array.sort()函数时,我的IDE(Webstorm)抛出错误:) TS2362: The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.(TS2362:算术运算的左侧必须为'any','number','bigint'或枚举类型。) Underscore version(下划线版本) this.interviewDetails.data = _.sortBy(this.interviewDetails.data, function (o) { return new Date(o.timeslot); }); Vanilla version(香草版) this.interviewDetails.data.sort((a: any, b: any) => new Date(a.timeslot) - new Date(b.timeslot)); 在此处输入图片说明 Can anybody help me what's possibly wrong here?(有人可以帮我这里有什么问题吗?) PS- Please see the red underlines in new Date(a.timeslot) in the image above(PS-请在new Date(a.timeslot)中看到红色下划线)   ask by Yashwardhan Pauranik translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...