当前位置:网站首页>Given an array composed of numbers, realize the name whose output ID is a number and sorted from small to large
Given an array composed of numbers, realize the name whose output ID is a number and sorted from small to large
2022-07-23 21:41:00 【Wei Xiao】
Given an array of numbers , Achieve output id Is the number , And sort from small to large name( Please use es6 grammar )
JavaScript
// Invoke the sample
const source = [
{
id: 4, name: 'test1' },
{
id: {
}, name: 'ssdf' },
"test",
{
id: () => {
}, name: 'sf' },
{
id: '6', name: 'test3' },
{
id: 6, name: 'test4' },
{
id: 7, name: 'test7' },
{
id: 2, name: 'test2' },
{
name: 'sf' },
{
},
]
// Method 1 :
function filterSort(source) {
// Write down your code
let arr = []
newValue = source.filter((v, i) => {
return typeof (v.id) == 'number'
})
newValue.sort(function (a, b) {
return a.id - b.id
})
for (v of newValue) {
arr.push(v.name)
}
return arr
}
// Method 2 :
function filterSort(arr) {
// Write down your code
return arr.filter(item => item.id === +item.id).sort((a,b)=>a.id-b.id).map(item=>item.name);
}
filterSort(source)
// The output is as follows
['test2', 'test1', 'test4', 'test7']
边栏推荐
- 二分函数细节
- Providers and consumers tags in zfoo
- [arXiv] notes on uploading papers for the first time
- C——文件
- NLP field history most complete must read classic papers classification, sorting and sharing (with Chinese analysis)
- prime_ series_ level-1
- 节流和防抖的说明和实现
- Improving performance with explicit rendering
- Synchro esp32c3 Hardware Configuration Information serial port Print Output
- Cookie 和 Session
猜你喜欢

Union and union all of Hana SQL

05_ UE4 advanced_ Material UV scaling

High numbers | calculation of triple integral 1 | high numbers | handwritten notes

& 9 nodemon automatic restart tool

壹沓数字机器人入选Gartner《中国AI市场指南》

Problems and abuse of protocol buffers

Construction and application progress of ten billion level knowledge map of meituan brain

Looking for the missing class name

合宙ESP32C3硬件配置信息串口打印輸出

Typescript Basics
随机推荐
Tell me the top ten securities companies? Is it safe to open an account online?
手机测试相关基础知识
[attack and defense world web] difficulty four-star 12 point advanced question: flatscience
PCL出错:error C2589“(“:“::“右边的非法标记)
Sword finger offer Second Edition: string (simple)
北大清华2022年在各地录取人数排名
[complex overloaded operator]
Is it safe to open a securities account online?
Edge cloud | 1. overview
合宙ESP32C3硬件配置信息串口打印輸出
Cesium core class viewer viewer details
Openlayers instance animated GIF GIF animation
阿里onedate分层思想
C - documents
js 对象数组去重
Proof of green Tao theorem (1): preparation, notation and Gowers norm
First acquaintance with JS (programming suitable for beginners)
Hezhou esp32c3 hardware configuration information serial port printout
博客总排名为918
Chapter1 data cleaning