DEV Community

Chinwendu Agbaetuo
Chinwendu Agbaetuo

Posted on

1 1 1 1 1

Creating functions in JavaScript - Part 4

Write a function called createWrapper that takes a prefix and a suffix, and returns a new function that adds the prefix and suffix to a provided string.

function createWrapper (prefix, suffix) {
  return function (text) {
    return prefix + text + suffix;
  } 
}

let bracketWrapper = createWrapper(" [", "]");
console.log(bracketWrapper("Close me with brackets!"));

let bracesWrapper = createWrapper("{", "} ");
console.log(bracesWrapper("Curl me in!"));
Enter fullscreen mode Exit fullscreen mode
> " [Close me with brackets!]"
> "{Curl me in!} "
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more