let sortStr = new RegExp('Договорная', 'mgi')
if(sortStr.test(a.price) && !sortStr.test(b.price)) {
return a.price < b.price
}else if(!sortStr.test(a.price) && sortStr.test(b.price)){
return a.price > b.price
}else if(!sortStr.test(a.price) && !sortStr.test(b.price)){
return a.price === b.price
}else{
return a.price - b.price
}
let sortStr = new RegExp('^[0-9]+', 'mgi')
if(a.price.search(sortStr) !== -1 && b.price.search(sortStr) === -1) {
return a.price < b.price
}else if(a.price.search(sortStr) === -1 && b.price.search(sortStr) !== -1){
return a.price > b.price
}else if(a.price.search(sortStr) === -1 && b.price.search(sortStr) === -1){
return a.price === b.price
}else{
return a.price - b.price
}
function isString (obj) {
return (Object.prototype.toString.call(obj) === '[object String]');
}
function compare( a, b ) {
if((isString(a.price) && isString(b.price)) || (!isString(a.price) && !isString(b.price))){
if(a.price>b.price)
return 1;
if(a.price<b.price)
return -1;
}
if((isString(a.price) && !isString(b.price)) || (!isString(a.price) && isString(b.price)))
return isString(a.price)?-1:1
return 0;
}
function sorter(map) {
var data = [];
for (var key in map) data.push(map[key]);
data.sort(compare);
var sorted= {};
data.forEach(function (el,index) {
sorted[index]=el;
});
return sorted;
}