5 kyu

String insert values

884 of 891ankr

Description:

Given a string and an object/array you need to return a formatted string. Replace all occurrences in the string where the name of a key in the object is surrounded by curly brackets.

Inherited object properties should not be applied

An example says more than a thousand words..

Example using object

var s = 'Hello {foo} - make me a {bar}';
var o = {
  foo : 'Jack',
  bar : 'sandwich'
};

format(s, o); // "Hello Jack - make me a sandwich"

Example using array

var s = 'Hello {0} - make me a {1}';
var a = ['Jack', 'sandwich'];

format(s, a); // "Hello Jack - make me a sandwich"

See tests for more information.

Strings
Algorithms

Stats:

CreatedDec 1, 2013
PublishedDec 1, 2013
Warriors Trained1873
Total Skips72
Total Code Submissions4974
Total Times Completed891
JavaScript Completions884
Total Stars34
% of votes with a positive feedback rating81% of 131
Total "Very Satisfied" Votes94
Total "Somewhat Satisfied" Votes23
Total "Not Satisfied" Votes7
Ad
Contributors
  • ankr Avatar
  • jhoffner Avatar
Ad