Questions
7.1. Sum as you will. The following exercise will help you understand some of the concepts we dealt with above, even if you solve it without using any of the functions we saw in the chapter. Write a sumMany()
function that lets you sum an indeterminate quantity of numbers, in the following fashion. Note that when the function is called with no arguments, the sum is returned:
let result = sumMany((9)(2)(3)(1)(4)(3)()); // 22
7.2. Working stylishly. Write an applyStyle()
function that will let you apply basic styling to strings, in the following way. Use either currying or partial application:
const makeBold = applyStyle("b"); document.getElementById("myCity").innerHTML = makeBold("Montevideo"); // <b>Montevideo</b>, to produce Montevideo const makeUnderline = applyStyle("u"); document.getElementById("myCountry").innerHTML = makeUnderline("Uruguay"); // <u>Uruguay</u>, to produce Uruguay
7.3. Currying...