<script> function fn(b, a) { a = a.slice(); b = b.slice(); return a.filter(function(a) { return !~b.indexOf(a) }) }; document.write(fn([5,3,2,1],[1,2,3,4,5,6,7])+"<br>"); </script>