Created
February 26, 2017 08:18
-
-
Save Underdoge/7457e5ccdc7f3ebe5fc16418600e3276 to your computer and use it in GitHub Desktop.
sortByHeight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sortByHeight(a) { | |
var b=a.slice(0); | |
var x=0; | |
for (var i=0;i<b.length;i++){ | |
if(b[i]<0){ | |
b.splice(i,1); | |
} | |
} | |
b.sort((a,b)=>a-b); | |
for (var j=0;j<a.length;j++){ | |
if(a[j]>=0){ | |
a[j]=b[x]; | |
x++; | |
} | |
} | |
return a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment