- 226.3k
- 56
- 496
- 504
It doesn’t seem conveniently possible. What can you do? Something horrible, as always.
constlet tuple = (function() => {
const let map = new Map();
returnfunction tuple(...args) => {
let current = map;
let args = Object.freeze(argsArray.prototype.slice.call(arguments));
for (constlet item of args) {
if (current.has(item)) {
current = current.get(item);
} else {
const let next = new Map();
current.set(item, next);
current = next;
}
}
if (!current.final) {
current.final = args;
}
return current.final;
};
return tuple;
})();
And voilà.
let m = new Map();
m.set(tuple(3, 5), [tuple(3, 5, 3), tuple(3, 5, 4)]);
m.get(tuple(3, 5)); // [[3, 5, 3], [3, 5, 4]]
It doesn’t seem conveniently possible. What can you do? Something horrible, as always.
const tuple = (() => {
const map = new Map();
return (...args) => {
let current = map;
Object.freeze(args);
for (const item of args) {
if (current.has(item)) {
current = current.get(item);
} else {
const next = new Map();
current.set(item, next);
current = next;
}
}
if (!current.final) {
current.final = args;
}
return current.final;
};
})();
And voilà.
let m = new Map();
m.set(tuple(3, 5), [tuple(3, 5, 3), tuple(3, 5, 4)]);
m.get(tuple(3, 5)); // [[3, 5, 3], [3, 5, 4]]
It doesn’t seem conveniently possible. What can you do? Something horrible, as always.
let tuple = (function() {
let map = new Map();
function tuple() {
let current = map;
let args = Object.freeze(Array.prototype.slice.call(arguments));
for (let item of args) {
if (current.has(item)) {
current = current.get(item);
} else {
let next = new Map();
current.set(item, next);
current = next;
}
}
if (!current.final) {
current.final = args;
}
return current.final;
}
return tuple;
})();
And voilà.
let m = new Map();
m.set(tuple(3, 5), [tuple(3, 5, 3), tuple(3, 5, 4)]);
m.get(tuple(3, 5)); // [[3, 5, 3], [3, 5, 4]]
- 431
- 4
- 11
It doesn’t seem conveniently possible. What can you do? Something horrible, as always.
letconst tuple = (function() => {
letconst map = new Map();
functionreturn tuple(...args) => {
let current = map;
let args = Object.freeze(Array.prototype.slice.call(arguments)args);
for (letconst item of args) {
if (current.has(item)) {
current = current.get(item);
} else {
letconst next = new Map();
current.set(item, next);
current = next;
}
}
if (!current.final) {
current.final = args;
}
return current.final;
}
return tuple;;
})();
And voilà.
let m = new Map();
m.set(tuple(3, 5), [tuple(3, 5, 3), tuple(3, 5, 4)]);
m.get(tuple(3, 5)); // [[3, 5, 3], [3, 5, 4]]
It doesn’t seem conveniently possible. What can you do? Something horrible, as always.
let tuple = (function() {
let map = new Map();
function tuple() {
let current = map;
let args = Object.freeze(Array.prototype.slice.call(arguments));
for (let item of args) {
if (current.has(item)) {
current = current.get(item);
} else {
let next = new Map();
current.set(item, next);
current = next;
}
}
if (!current.final) {
current.final = args;
}
return current.final;
}
return tuple;
})();
And voilà.
let m = new Map();
m.set(tuple(3, 5), [tuple(3, 5, 3), tuple(3, 5, 4)]);
m.get(tuple(3, 5)); // [[3, 5, 3], [3, 5, 4]]
It doesn’t seem conveniently possible. What can you do? Something horrible, as always.
const tuple = (() => {
const map = new Map();
return (...args) => {
let current = map;
Object.freeze(args);
for (const item of args) {
if (current.has(item)) {
current = current.get(item);
} else {
const next = new Map();
current.set(item, next);
current = next;
}
}
if (!current.final) {
current.final = args;
}
return current.final;
};
})();
And voilà.
let m = new Map();
m.set(tuple(3, 5), [tuple(3, 5, 3), tuple(3, 5, 4)]);
m.get(tuple(3, 5)); // [[3, 5, 3], [3, 5, 4]]
It doesn’t seem conveniently possible. What can you do? Something horrible, as always.
let tuple = (function() {
let map = new Map();
function tuple() {
let current = map;
let args = Object.freeze(Array.prototype.slice.call(arguments));
for (let item of args) {
if (current.has(item)) {
current = current.get(item);
} else {
let next = new Map();
current.set(item, next);
current = next;
}
}
if (!current.final) {
current.final = args;
}
return current.final;
}
return tuple;
})();
And voilà.
let m = new Map();
m.set(tuple(3, 5), [tuple(3, 5, 3), tuple(3, 5, 4)]);
m.get(tuple(3, 5)); // [[3, 5, 3], [3, 5, 4]]