Recently, I've been attempting to transform a string into an array of numbers[], however, my lack of experience with TypeScript has led me to struggle with properly typing my code to satisfy the TypeScript compiler...
My objective is as follows:
matString.split(/[\n ]/).reduce((acc, cur, index) => acc[index] = Number(cur));
Despite numerous attempts at defining types, such as this one, I haven't been able to get it working :(
matString.split(/[\n ]/).reduce((acc: Array<number>, cur, index) => acc[index] = Number(cur)) as Array<number>;
For some background, this piece of code takes in a matrix as a string and I'm looking to convert it into an array for further processing. While I have faced similar challenges before and found workarounds, I am determined to grasp the fix this time.
If it helps clarify my issue, here is a snapshot of my code accompanied by the error reported by the compiler: code image with error
This forms part of my solution to the problem outlined in this exercise found on exercism.