Ok, here's an approach which does not use the '-' symbol at all. And it doesn't cheat by computing Math.cos(Math.PI) either. The big catch is that it only works on integers. But that's one of the conditions of your original requirements, so that's ok. function getMax(a, b) { var originalA = a; var originalB = b; var negativeTestA = Math.log(a) var negativeTestB = Math.log(b) if (isNaN(negativeTestA) && !isNaN(negativeTestB)) { return b; } else if (!isNaN(negativeTestA) && isNaN(negativeTestB)) { return a; } a = Math.abs(a); b = Math.abs(b); var sparseList = []; sparseList[a] = [originalA]; if (sparseList[b]) { // Equality return originalA; } sparseList[b] = [originalB]; if (isNaN(negativeTestA) && isNaN(negativeTestB)) { // Loop through the list looking for the first element. var i = 0; while (!sparseList[i]) { i++; } return sparseList[i][0]; } else { // Return the last element on the list. return sparseList.pop()[0]; } }