var milkResponses: string[] = ["I like milk", "mmmm"];
function randomArrayShuffle(array) {
var currentIndex = array.length, temporaryValue, randomIndex;
while (0 !== currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
What I want to do is randomize a string array such as milkResponses, but the array parameter has an error saying that Parameter 'array' implicitly has an 'any' type. I'm not sure what it means. I think its because I made the array wrong?
Appreciate the help
If there's nothing that either explicitly sets the type of something in TypeScript, or a reliable way for TypeScript to infer that type (e.g. by creating a variable and immediately setting it to a value), then TypeScript will implicitly give it the type any. By default, TypeScript is configured to not allow code containing any implicit any to compile, which is why you're seeing this error.
Because it's a function argument without a default value, you'll want to specify its value explicitly. It looks like your function can operate on arrays that contain anything, so you probably want to use function randomArrayShuffle(array: any[]) {