【JavaScript】将浮点数与整数分开
function f(a, b) { if (a > Math.floor(a)) return 1; if (b > Math.floor(b)) return -1; } var a = [3.222, 1.234, 3, 2.1111, 5, 7, 6]; a.sort(f); document.write(a);
3,5,7,6,3.222,1.234,2.1111
本文来自博客园,作者:木子欢儿,转载请注明原文链接:https://www.cnblogs.com/HGNET/p/15585351.html