Get Random List Element

node v10.24.1
version: 1.0.0
endpointsharetweet
const { length, list, nth, List } = require("list") const random = function (l) { return nth(Math.floor(Math.random() * length(l)), l) } List.prototype.random = function () { return nth(Math.floor(Math.random() * length(this)), this) } const aList = list(1, 2, 3, 4) ; [ random(aList) , aList.random() ]
Loading…

no comments

    sign in to comment