Ipalibo
BAN USER
- 2of 2 votes
AnswersAn efficient way to sort patient files in an array of just 3 types 'High-importance', 'Mid-importance', 'Low-importance' which are in an arbitrary order (unsorted).
- Ipalibo in United States
The output preference should start with the highest.
1. High-importance
2. Mid-importance
3. Low-importance
[high,low,low,med,high,low]
ps I was told to take advantage of the fact that they are just only 3 types.| Report Duplicate | Flag | PURGE
Facebook Software Engineer / Developer Sorting
My answer to this question was using recursion:
var tmp = [];
(function addToArray(arr, toAdd){
if(!arr.length && !toAdd){
return;
}
if(!arr.length && toAdd){
arr = [0]
}
tmp.push(Math.floor((arr[arr.length-1]+toAdd)%10));
var _toAdd = Math.floor((arr[arr.length-1]+toAdd)/10)
_toAdd = (_toAdd < 0 ? 0 : _toAdd);
addToArray(arr.splice(0,arr.length-1), _toAdd);
})([0], 2);
console.log(tmp.reverse());
- Ipalibo November 20, 2017