If the template species a property that is not dened in the dictionary object

If the template species a property that is not dened

This preview shows page 3 - 5 out of 5 pages.

If the template speci±es a property that is not de±ned in the dictionary object, the property should be replaced with an empty string. If the property is between two words, you'll notice that replacing the property with an empty string will result in two consecutive whitespaces. Example: "This {{undefinedProperty}} // Invoking cs142MakeMultiFilter() with originalArray = [1,2,3] returns a function, saved //that can be used to repeatedly filter the input array var arrayFilterer1 = cs142MakeMultiFilter([1,2,3]); // call arrayFilterer1 (with callback function) to filter out all the numbers not equal to arrayFilterer1(function (elem) { return elem !== 2; // check if element is not equal to 2 }, function (currentArray) { console.log(this); // printing 'this' within the callback function should print original console.log(currentArray); // prints [1, 3] }); // call arrayFilterer1 (without callback function) to filter out all the elements not equa arrayFilterer1(function (elem) { return elem !== 3; // check if element is not equal to 3 }); // calling arrayFilterer1 with no filterCriteria should return the currentArray var currentArray = arrayFilterer1(); console.log('currentArray', currentArray); // prints [1] since we filtered out 2 and 3 // Since arrayFilterer returns itself, calls can be chained function filterTwos(elem) { return elem !== 2; } function filterThrees(elem) { return elem !== 3; } var arrayFilterer2 = cs142MakeMultiFilter([1,2,3]); var currentArray2 = arrayFilterer2(filterTwos)(filterThrees)(); console.log('currentArray2', currentArray2); // prints [1] since we filtered out 2 and 3 // Multiple active filters at the same time var arrayFilterer3 = cs142MakeMultiFilter([1,2,3]); var arrayFilterer4 = cs142MakeMultiFilter([4,5,6]); console.log(arrayFilterer3(filterTwos)()); // prints [1,3] console.log(arrayFilterer4(filterThrees)()); // prints [4,5,6]
Image of page 3
is cool" -> "This is cool" . This is ±ne. You do not have to worry about getting rid of the extra whitespace. Your system need only handle properly formatted properties. Its behavior can be left unde±ned in the following cases as we will not be checking explicitly for them. nested properties - {{foo {{bar}}}} or {{{{bar}}}} or {{{bar}}} unbalanced brackets - {{bar}}} stray brackets in any property string - da{y or da}y The following code shows how one might make use of the functions you de±ne in this problem: Problem 3: Fix cs142-test-project2.js to not pollute the global namespace (5 points) The test JavaScript ±le we give you ( cs142-test-project2.js ) declares numerous symbols in the global JavaScript namespace. For example, after the script is loaded the symbol p1Message appears in the global namespace. Another JavaScript ±le would then be able to access and change p1Message . Change cs142- test-project2.js to use the standard JavaScript module pattern using an anonymous function to hide symbols in the global namespace yet keep the same checking functionality.
Image of page 4
Image of page 5

You've reached the end of your free preview.

Want to read all 5 pages?

  • Fall '14
  • JeannetteE.Myers
  • Closure, currentArray

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture