From b817a19326b67668ee1026d7cc52781666ec44b7 Mon Sep 17 00:00:00 2001 From: Amine El Baghdadi <75886237+NoobJsPerson@users.noreply.github.com> Date: Sat, 15 May 2021 18:30:55 +0000 Subject: update main.js --- main.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 789c316..e4883d9 100644 --- a/main.js +++ b/main.js @@ -1,5 +1,15 @@ -/* Import the interpolate function*/ -import interpolate from "interpolate.js"; +/* Define the interpolate function */ +function interpolate(template, variables) { + return template.replace(/\${[^{]+}/g, (match) => { + const path = match.slice(2, -1).trim(); + return getObjPath(path, variables); + }); +} + +/* Get the specified property or nested property of an object */ +function getObjPath(path, obj) { + return path.split('.').reduce((res, key) => res[key], obj); +} /* Compute the total duration of the run. */ function compute() { -- cgit v1.2.3