Try to do something with array with unpredictable result, something like return random member of filtered array
let tempArr = [1,2,3,4,5].filter(x=>x>2);
return tempArr[Math.floor(Math.random()*tempArr.length)]; // 3, 4 or 5
Just want to make it more clear by using chain function, but the following code is not working, this.length
is always 1
return [1,2,3,4,5]
.filter(x=>x>2)
.at(Math.floor(Math.random()*this.length)); // always returns `3`
What's the correct way to do this?