# Typescript - Generic Object Types https://www.typescriptlang.org/docs/handbook/2/objects.html ``` interface ArrayType<Type> { length: number; slice(start: number, end: number): Type; } function getShuffledArray<Type extends ArrayType<Type>>(array: Type): Type { for (let i = array.length - 1; i > 0; i -= 1) { const j = Math.floor(Math.random() * (i + 1)); const temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; } function getArrayPart<Type extends ArrayType<Type>>(array: Type, startIndex: number, endIndex: number): Type { if (endIndex > array.length) { return array.slice(startIndex, array.length); } return array.slice(startIndex, endIndex); } ``` ###### tags: `typescript` `generics`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up