Nice, simple solution that can be easily adapted for lessThan and equals. Depending on your use case, you may want to add a check for array length, as
coffee> [0, 9].greaterThan [0, 8, 1]
true
Assuming you wanted to consider longer arrays to be greater, the following modification should work.
Array::greaterThan = (otherArray) ->
thisLen = this.length
otherLen = otherArray.length
if thisLen isnt otherLen
return thisLen > otherLen
for element, index in @ when element isnt otherArray[index]
return element > otherArray[index]
false
Nice, simple solution that can be easily adapted for lessThan and equals. Depending on your use case, you may want to add a check for array length, as
Assuming you wanted to consider longer arrays to be greater, the following modification should work.