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
Similar Kata:
Stats:
Created | Dec 1, 2013 |
Published | Dec 1, 2013 |
Warriors Trained | 1873 |
Total Skips | 72 |
Total Code Submissions | 4974 |
Total Times Completed | 891 |
JavaScript Completions | 884 |
Total Stars | 34 |
% of votes with a positive feedback rating | 81% of 131 |
Total "Very Satisfied" Votes | 94 |
Total "Somewhat Satisfied" Votes | 23 |
Total "Not Satisfied" Votes | 7 |