How to use the @mathigon/core.last function in @mathigon/core

To help you get started, we’ve selected a few @mathigon/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mathigon / textbooks / content / graph-theory / functions.js View on Github external
$ut.on('pointerenter', function() {
      if (!map.drawing || currentUtility === $ut) return;
      map.addPoint(p);
      map.stop();
      map.p = null;
      $ut.effect('pulse-down');
      if (startUtility.data.type === dataType) {
        last(map.paths).css('stroke','#C00');
        errors.push(last(map.paths));
        if (dataType === 'house') {
          $section.addHint('housesToEachOther');
        } else {
          $section.addHint('factoriesToEachOther');
        }
      } else {
        let sector = (startUtility.data.type === 'house') ?
          $('.' + $ut.data.utility, currentUtility) : $('.' + currentUtility.data.utility, $ut);
        sector.css('opacity', 1);
        sectors.set(last(map.paths), sector);
      }
      // TODO Error on connect twice
    });
  });
github mathigon / textbooks / content / graph-theory / functions.ts View on Github external
map.p = undefined;
      $ut.effect('pulse-down');
      if (startUtility.data.type === dataType) {
        last(map.paths).css('stroke', '#C00');
        errors.push(last(map.paths));
        if (dataType === 'house') {
          $section.addHint('housesToEachOther');
        } else {
          $section.addHint('factoriesToEachOther');
        }
      } else {
        let sector = (startUtility.data.type === 'house') ?
                     $('.' + $ut.data.utility, currentUtility)! :
                     $('.' + currentUtility.data.utility, $ut)!;
        sector.css('opacity', 1);
        sectors.set(last(map.paths), sector);
      }
      // TODO Error on connect twice
    });
  }
github mathigon / textbooks / content / graph-theory / functions.js View on Github external
$ut.on('pointerenter', function() {
      if (!map.drawing || currentUtility === $ut) return;
      map.addPoint(p);
      map.stop();
      map.p = null;
      $ut.effect('pulse-down');
      if (startUtility.data.type === dataType) {
        last(map.paths).css('stroke','#C00');
        errors.push(last(map.paths));
        if (dataType === 'house') {
          $section.addHint('housesToEachOther');
        } else {
          $section.addHint('factoriesToEachOther');
        }
      } else {
        let sector = (startUtility.data.type === 'house') ?
          $('.' + $ut.data.utility, currentUtility) : $('.' + currentUtility.data.utility, $ut);
        sector.css('opacity', 1);
        sectors.set(last(map.paths), sector);
      }
      // TODO Error on connect twice
    });
  });
github mathigon / textbooks / content / graph-theory / functions.ts View on Github external
$ut.on('pointerenter', () => {
      if (!map.drawing || currentUtility === $ut) return;
      map.addPoint(p);
      map.stop();
      map.p = undefined;
      $ut.effect('pulse-down');
      if (startUtility.data.type === dataType) {
        last(map.paths).css('stroke', '#C00');
        errors.push(last(map.paths));
        if (dataType === 'house') {
          $section.addHint('housesToEachOther');
        } else {
          $section.addHint('factoriesToEachOther');
        }
      } else {
        let sector = (startUtility.data.type === 'house') ?
                     $('.' + $ut.data.utility, currentUtility)! :
                     $('.' + currentUtility.data.utility, $ut)!;
        sector.css('opacity', 1);
        sectors.set(last(map.paths), sector);
      }
      // TODO Error on connect twice
    });
  }
github mathigon / textbooks / probability / functions.js View on Github external
function generatePossibilities(len) {
    if (len <= 1) return [['R', 'B']];
    let prev = generatePossibilities(len - 1);
    prev.push(last(prev).map(x => x + 'R').concat(last(prev).map(x => x + 'B')));
    return prev;
  }
github mathigon / textbooks / content / sequences / functions.ts View on Github external
while (n0 > 0) {
    let r1 = x - triangleNumber(n0);
    if (!r1) return [n0, 0, 0];
    let n1 = Math.min(n0, Math.floor((Math.sqrt(8 * r1 + 1) - 1) / 2));
    while (n1 > 0) {
      let r2 = r1 - triangleNumber(n1);
      if (!r2) results.push([n0, n1, 0]);
      let n2 = Math.min(n1, Math.floor((Math.sqrt(8 * r2 + 1) - 1) / 2));
      if (r2 === triangleNumber(n2)) results.push([n0, n1, n2]);
      n1 -= 1;
    }
    n0 -= 1;
  }

  sortBy(results, r => total(r.map(x => x * x)));
  return last(results);
});
github mathigon / textbooks / content / graph-theory / components / sketch.ts View on Github external
checkForIntersects() {
    if (!this.options.intersect || this.paths.length <= 1) return;

    let path1 = last(this.paths);
    let points1 = path1.points as Point[];
    let line1 = new Segment(points1[points1.length - 2],
        points1[points1.length - 1]);

    for (let i = 0; i < this.paths.length - 1; ++i) {
      let path2 = this.paths[i];
      let points2 = path2.points as Point[];
      for (let j = 1; j < points2.length - 2; ++j) {
        let line2 = new Segment(points2[j], points2[j + 1]);
        let t = Segment.intersect(line1, line2);
        if (t) {
          this.trigger('intersect', {point: t, paths: [path1, path2]});
          return;
        }
      }
    }
github mathigon / boost.js / src / sketch.js View on Github external
checkForIntersects() {
    if (!this.options.intersect || this.paths.length <= 1) return;

    let path1 = last(this.paths);
    let points1 = path1.points;
    let line1 = new Line(points1[points1.length-2], points1[points1.length-1]);

    for (let i = 0; i < this.paths.length - 1; ++i) {
      let path2 = this.paths[i];
      let points2 = path2.points;
      for (let j = 1; j < points2.length - 2; ++j) {
        let line2 = new Line(points2[j], points2[j + 1]);
        let t = Line.intersect(line1, line2);
        if (t) {
          this.trigger('intersect', { point: t, paths: [path1, path2] });
          return;
        }
      }
    }
  }