let [withAge, withoutAge] = users.reduce((agg, v) => {
agg['age' in v].push(v)
return agg
}, [[], []])
const sorted = [...withAge.sort((a, b) => a.age - b.age), ...withoutAge]
let [withoutAge, withAge] = _.partition(users, ({ age }) => age)
const sorted = [..._.sort(withAge, 'age'), ...withoutAge]
<table>
<tr>
<td><div class="draggable">0</div></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td><div class="draggable">1</div></td>
<td><div class="draggable">2</div></td>
</tr>
<tr>
<td></td>
<td><div class="draggable">3</div></td>
<td></td>
</tr>
</table>
td {
border: 1px solid silver;
width: 100px;
height: 100px;
}
.draggable {
display: inline-block;
width: 25px;
height: 25px;
background: red;
cursor: pointer;
margin: 5px;
color: white;
}
$('.draggable').draggable({
containment: 'table',
stop(e, ui) {
$(this).css({
left: '',
top: '',
});
},
});
$('td').droppable({
accept: '.draggable',
drop(e, ui) {
ui.draggable.appendTo(this);
},
});