Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Answer

Rollback to Revision 1 - Edit approval overridden by post owner or moderator
Source Link
Ry-
  • 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]]

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]]
Source Link
Ry-
  • 226.3k
  • 56
  • 496
  • 504

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]]
lang-js

AltStyle によって変換されたページ (->オリジナル) /