const intToArray = (value: number) => {
  const array = []
  for (let i = 1; i <= value; i++) {
    array.push(i)
  }

  return array
}

const splitInChunks = (array: number[], chunkSize: number) => {
  const chunks = []
  for (let i = 0, j = array.length; i < j; i += chunkSize) {
    const temparray = array.slice(i, i + chunkSize)
    chunks.push(temparray)
  }

  return chunks
}

const findChunk = (chunks: number[][], page: number) => {
  for (let i = 0; i < chunks.length; i++) {
    for (let j = 0; j < chunks[i].length; j++) {
      if (chunks[i][j] === page) {
        return {
          index: i,
          items: chunks[i]
        }
      }
    }
  }

  return {
    index: 0,
    items: chunks[0]
  }
}

export {
  intToArray,
  splitInChunks,
  findChunk
}