5 kyu
String insert values
896 of 903ankr
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 | 1907 |
Total Skips | 72 |
Total Code Submissions | 5004 |
Total Times Completed | 903 |
JavaScript Completions | 896 |
Total Stars | 34 |
% of votes with a positive feedback rating | 80% of 133 |
Total "Very Satisfied" Votes | 94 |
Total "Somewhat Satisfied" Votes | 24 |
Total "Not Satisfied" Votes | 8 |