Pinned Loading
-
setdefault but for JavaScript. setde...
setdefault but for JavaScript. setdefault is a function in Python which can be used to get around using a defaultdict. Here I recreate the behavior in JavaScript. 1const getDefault = (o, key, defaultVal) => key in o ? o[key] : o[key] = defaultVal
23// Prototype version of above. Allows for usage: o.getDefault(key, def)
4Object.defineProperty(Object.prototype, "getDefault", {
5value: function(key, defaultVal) {
-
range function for JavaScript. range...
range function for JavaScript. range is a function that's central to Python that I've implemented in JS. Here, it's a generator just like how it is in Python. Works with negative number arguments. 1function* range(start, stop, step=1) {
2if(typeof stop === 'undefined') [start, stop] = [0, start]
3for(let i = start; step > 0 ? i < stop : i > stop; i += step)
4yield i
5}
Something went wrong, please refresh the page to try again.
If the problem persists, check the GitHub status page or contact support.
If the problem persists, check the GitHub status page or contact support.