String insert values

This commit is contained in:
2020-01-29 09:23:55 +01:00
parent 425a0cf1fc
commit 9eb4e9f9f7

View File

@@ -0,0 +1,6 @@
// https://www.codewars.com/kata/529b54d9aba78c924d00088e/javascript
const format = function (str, obj) {
const truthy = (val, def) => typeof val === 'undefined' ? def : val;
return str.replace(/\{\w+\}/g, a => truthy(obj[a.slice(1, a.length-1)], a));
};