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
Polyfill for Bind
00:00
5 left

Polyfill for Bind

HardPython

Problem

Implement a polyfill for Function.prototype.bind.

For this exercise, represent the target function with a JSON object containing an operation, and implement bind_polyfill(function_spec, this_arg, bound_args, call_args) to model binding and invocation. The result must apply this_arg, prepend bound_args before call_args, and support regular calls only; for example, a sum operation with base 10, bound arguments [5], and call arguments [3] returns 18, while a context-returning operation with null returns null.

Constraints

  • function_spec is a dictionary with an operation from sum_context, format_context, collect, return_context, or multiply_context.
  • this_arg is a JSON value, including a dictionary, string, number, boolean, or null.
  • bound_args and call_args are lists of JSON values.
  • The target is invoked as a regular function. Constructor behavior and JavaScript primitive boxing are out of scope.
  • The total number of bound and call arguments is at most 10^4.

Function Signature

def bind_polyfill(function_spec, this_arg, bound_args, call_args):
Interviewer

Your question is Polyfill for Bind. 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.