Creating functions in JavaScript – Part 4

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!"));
> " [Close me with brackets!]"
> "{Curl me in!} "
Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
fulfillment-centers-for-drop-shipping

Fulfillment Centers for Drop Shipping

Next Post
using-typedef

Using typedef

Related Posts