Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
</body>
</html>
  
 
var order = ['small', 'small', 'medium', 'medium', 'big'];
var arr = [
  'small',
  'small',
  'small',
  'small',
  'medium',
  'medium',
  'medium',
  'medium',
  'big',
  'big'
];
function orderBy(arr, order) {
  var result = [],
      i = 0, len = arr.length,
      index;
  
  while (result.length < len) {
    index = arr.indexOf(order[i]);
    result.push(arr[index]);
    arr.splice(index, 1);
    i = i >= order.length-1 ? 0 : ++i;
  }
  
  return result;
}
console.log(orderBy(arr, order));
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
elclanrspro
0viewers