Talentd
FleetCode

2690. Infinite Method Object

Easy92.3% acceptancePremium elsewhere, free here

Write a function that returns an infinite-method object.

An infinite-method object is defined as an object that allows you to call any method and it will always return the name of the method.

For example, if you execute obj.abc123(), it will return "abc123".

Example 1:

Input: method = "abc123"
Output: "abc123"
Explanation:
const obj = createInfiniteObject();
obj['abc123'](); // "abc123"
The returned string should always match the method name.

Example 2:

Input: method = ".-qw73n|^2It"
Output: ".-qw73n|^2It"
Explanation: The returned string should always match the method name.

Constraints:

  • 0 <= method.length <= 1000

Hints open one at a time

Hint 1
Javascript has the concept of Proxy. That concept is critical to this problem.
Hint 2
Override all "get" for the object. Return a function instead.
Hint 3
That function should return the "prop", i.e. the method name.
4:02
Still stuck?Read the written solution, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
"abc123"
Input
".-qw73n|^2It"
Your code is saved on this device.Solution