I wish to do this:
const ret = [];
nums.forEach(num => {
const dict = [];
dict[num] = Math.random() * 2 - 1;
ret.push(dict);
});
where nums = ["const_0", "const_1"] => ret = [{const_0: random_number}, {const_1: random_number}].
I want to do this using the map function, for no better reason other than practice using map functions. Here's my current attempt:
let ret = [];
ret = nums.map( x => new Object()[x] = Math.random() * 2 - 1);
but this returns ret = [random_number, random_number], it fails to create the dictionary/Object.