Skip to content

Instantly share code, notes, and snippets.

@eXeDK
Created January 4, 2015 17:03
Show Gist options
  • Save eXeDK/37f8a31c6cfff4979926 to your computer and use it in GitHub Desktop.
Save eXeDK/37f8a31c6cfff4979926 to your computer and use it in GitHub Desktop.
def dataPartition(data: Array[DataPoint], output: Array[Array[DataPoint]], defaultSize: Int, remainingRest: Int): Array[Array[DataPoint]] = {
if (data.nonEmpty) {
val thisPartitionSize = if (remainingRest > 0) { defaultSize + 1} else { defaultSize }
val nextRemainingRest = if (remainingRest > 0) { remainingRest - 1 } else { remainingRest }
val thisPartition = data.slice(0, thisPartitionSize)
val remainingData = data.drop(thisPartitionSize)
dataPartition(remainingData, output :+ thisPartition, defaultSize, nextRemainingRest)
} else {
output
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment