7 kyu

Run your String

Description:

  1. Function should accept two arguments:
  • arg: any type

  • object with properties:

    • param: string type.
    • func: string type. This string is a body of executable function
  1. Function should evaluate code of string passed as 'func' with parameter arg passed as argument and return result of execution

Example:

var arg = 4,                         // arg for "string" function call
    obj = {
      param: 'num',                  // parameter name for function in string  
      func: 'return Math.sqrt(num)'  // function that need call with arg var
    };
    
runYourString(arg, obj)              // we expect it should return 2 which is a result of square root of 4

ps: Solution of this Kata just fun language trick.

Usage of this code in production is not recommended.

Strings
Fundamentals

Stats:

CreatedJan 30, 2015
PublishedJan 30, 2015
Warriors Trained2760
Total Skips262
Total Code Submissions9202
Total Times Completed1555
JavaScript Completions1555
Total Stars43
% of votes with a positive feedback rating84% of 150
Total "Very Satisfied" Votes114
Total "Somewhat Satisfied" Votes24
Total "Not Satisfied" Votes12
Ad
Contributors
  • VoodooLab Avatar
  • joh_pot Avatar
Ad