SOURCE

let find = function(origin) {
    this.data = origin
}

find.prototype.where = function(criteria){
    const reg = criteria.title;
    this.data = this.data.filter(item=>{
        return reg.test(item.title)
    })
    return this
}

find.prototype.orderBy=function(key,order){
    this.data.sort((a,b)=>{
        if(order === 'asc'){
            return a[key]-b[key]
        } else {
            return b[key]-a[key]
        }
    })
    return this.data
}

var data = [
    {userId: 8, title:'title1'},
    {userId: 11, title:'other'},
    {userId: 15, title:null},
    {userId: 19, title:'title2'},
]

var result = new find(data).where({
    title:/\d$/
}).orderBy('userId','desc');

console.log(result)
console 命令行工具 X clear

                    
>
console