Appendix. Exercise answers

 

Lesson 4

{
  let DEFAULT_START = 0;
  let DEFAULT_STEP  = 1;

  window.mylib.range = function (start, stop, step) {
    let arr = [];

    if (!step) {
      step = DEFAULT_STEP;
    }

    if (!stop) {
      stop = start;
      start = DEFAULT_START;
    }

    if (stop < start) {
      // reverse values
      let tmp = start;
      start = stop;
      stop = tmp;
    }

    for (let i = start; i < stop; i += step) {
      arr.push(i);
    }

    return arr;
  }
}

Lesson 5

{
  const DEFAULT_START = 0;
  const DEFAULT_STEP  = 1;

  window.mylib.range = function (start, stop, step) {
    const arr = [];

    if (!step) {
      step = DEFAULT_STEP;
    }

    if (!stop) {
      stop = start;
      start = DEFAULT_START;
    }

    if (stop < start) {
      // reverse values
      const tmp = start;
      start = stop;
      stop = tmp;
    }

    for (let i = start; i < stop; i += step) {
      arr.push(i);
    }

    return arr;
  }
}

Lesson 6

function
maskEmail(email, mask) {
  if (!email.includes('@')) {
    throw new Error('Invalid Email');
  }
  if (!mask) {
    mask = '*';
  }
  const atIndex = email.indexOf('@');
  const masked = mask.repeat(atIndex);
  const tld = email.substr(atIndex);

  return masked + tld;
}

Lesson 7

Lesson 9

Lesson 10

Lesson 11

Lesson 12

Lesson 13

Lesson 15

Lesson 16

Lesson 17

Lesson 18

Lesson 20

Lesson 21

Lesson 23

Lesson 24

Lesson 25

Lesson 27

Lesson 28