I want to insert duplicate values into array based on length provided like this:
var a = [{displayName: 'bar'}, {displayName:'google'}, {displayName:'mod'}];;
var dataTypesLength= 4;
Output should be like:
var a = [{displayName: 'bar'},{displayName: 'bar'},{displayName: 'bar'},{displayName: 'bar'}, {displayName:'google'},{displayName:'google'},{displayName:'google'},{displayName:'google'}, {displayName:'mod'}, {displayName:'mod'}, {displayName:'mod'}, {displayName:'mod'}];
I tried this:
a = a.flatMap( word => Array.from({ dataTypesLength}).fill( word ));
but I am getting typescript error saying: Argument of type '{ dataTypesLength: any; }' is not assignable to parameter of type 'ArrayLike<{}>'.
Object literal may only specify known properties, and 'dataTypesLength' does not exist in type 'ArrayLike<{}>'
a, the other iterates1..4and pushes items froma. This is a straightforward and naive solution. As long as you have it working - you can see if you can turn it into composition of functions.dataTypesLengthproperty, not alengthproperty...