Python-like function parameters in JavaScript
I’m trying to emulate the functionality of random.choices in the Python standard library, in JavaScript. I tried this code: function choices(arr, weights = null, k = 1) { let out = []; if (weights != null) { // implemented later } else if (k == 1) { return arr[Math.floor(Math.random() * arr.length)] } else { for… Read More Python-like function parameters in JavaScript