Windows function

Warning

This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.

Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.

Namespace: Microsoft.Quantum.Arrays

Package: Microsoft.Quantum.Standard

Returns all consecutive subarrays of length size.

function Windows<'T> (size : Int, array : 'T[]) : 'T[][]

Description

This function returns all n - size + 1 subarrays of length size in order, where n is the length of arr. The first subarrays are arr[0..size - 1], arr[1..size], arr[2..size + 1] until the last subarray arr[n - size..n - 1].

If size <= 0 or size > n, an empty array is returned.

Input

size : Int

Length of the subarrays.

array : 'T[]

An array of elements.

Output : 'T[][]

Type Parameters

'T

The type of array elements.

Example

// same as [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
let windows = Windows(3, [1, 2, 3, 4, 5]);