Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Custom Bind Polyfill
00:00
5 left

Custom Bind Polyfill

EasyPython

Problem

Pocket FM uses callback-heavy interfaces for episode cards and playback controls. Implement a model of JavaScript's Function.prototype.bind that preserves a function's receiver context and supports partial application of arguments.

Because JSON cannot represent executable functions, the function is identified by a name. The supported functions are:

  • format_episode: reads this_arg["title"] and returns "<title>: <prefix><episode>".
  • progress_label: reads this_arg["duration"] and returns "<current>/<duration> <unit>".

Implement custom_bind(function_name, this_arg, bound_args, call_args). It must create a bound callable internally, prepend bound_args to call_args, invoke the selected function with this_arg as its receiver, and return the result.

Formal Specification

  • function_name: a string, either "format_episode" or "progress_label".
  • this_arg: a dictionary containing the context used by the selected function.
  • bound_args: a list of arguments captured when binding occurs.
  • call_args: a list of arguments supplied when the bound function is later called.
  • Return the value produced by the selected function.

Constraints

  • function_name is either "format_episode" or "progress_label"
  • this_arg contains the fields required by the selected function
  • 0 <= len(bound_args) <= 10
  • 0 <= len(call_args) <= 10
  • The combined arguments match the selected function's parameters

Function Signature

def custom_bind(function_name, this_arg, bound_args, call_args):
Interviewer

Your question is Custom Bind Polyfill. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
Code
Sign up free to run your codeLog inLn 2
Run your code to see test output here.