         @length - 1
     else
         r
+Array::_ratioToLength = (ratio) ->
+    r = Math.round(ratio * (@length + 1) - 0.5)
+    if r <= 0 # `<=` can correct -0
+        0
+    else if r > @length
+        @length
+    else
+        r
 Array::_reverseToIndex = (reverseIndex) ->
     @length - 1 - reverseIndex
 Array::_positionToIndex = (pos) ->

        @_ratioToIndex(pos.Ratio)
    else
        pos
Array::_numberToLength = (pos) -> if 0 < pos < 1 then pos = Math.round(pos * @length) else pos
Array::clone = -> @[..]
Array::isEmpty = -> @length == 0
Array::lazy = -> ArrayLazyWrapper(@)
Array::portion = (startIndex, length, endIndex) ->
    startIndex = @_positionToIndex(startIndex)
    length = @_numberToLength(length)
    endIndex = @_positionToIndex(endIndex)
    @slice(startIndex, if length? then startIndex + length else endIndex + 1)
Array::at = (index) ->

    r
Array::takeRandom = (count) ->
    count ?= @length
    count = @_amountToLength(count)
    repeat(count, => @takeRandomOne())
Array::removeAt = (index) ->
    @splice(index, 1)
