cubing/alg

cubing/alg is the part of cubing.js that lets you parse and work with algs.

String conversion

Parse an alg by passing it to the Alg constructor. You can call .toString() to get back a string representation.

import { Alg } from "https://cdn.cubing.net/js/cubing/alg"

const alg = new Alg("R U R' U R U2' R'");
console.log(alg);
console.log(alg.toString());
Alg {} "R U R' U R U2' R'"

As a convenience, you can use .log() to view an alg in a JavaScript console (e.g. node or DevTools). We'll use that for all the examples from now on:

import { Alg } from "https://cdn.cubing.net/js/cubing/alg"

new Alg("R U R' U R U2' R'").log();
Alg {} "R U R' U R U2' R'"

Note that this will result in a canonical string for the alg with whitespace collapsed.

import { Alg } from "https://cdn.cubing.net/js/cubing/alg"

const alg = new Alg(" R   U R'   U R U2'   R'");
alg.log();
Alg {} "R U R' U R U2' R'"

Methods

Alg objects are immutable (cannot be modified directly). If you want a modified version of an Alg, you can call its methods:

import { Alg } from "https://cdn.cubing.net/js/cubing/alg";

const commutator = new Alg("[R, [U': L']]");
commutator.expand().log();
Alg {} "R U' L' U R' U' L U"

import { Alg } from "https://cdn.cubing.net/js/cubing/alg";
const commutator = new Alg("[R, [U': L']]");

const niklas = commutator.concat("U'");
niklas.log();
niklas.expand().log();
niklas.expand().simplify({cancel: true}).log();
Alg {} "[R, [U': L']] U'" Alg {} "R U' L' U R' U' L U U'" Alg {} "R U' L' U R' U' L"

import { Alg } from "https://cdn.cubing.net/js/cubing/alg";

const sune = new Alg("[R U R2', [R: U]]");
const antiSune = sune.invert();
antiSune.log();
antiSune.expand().log();
Alg {} "[[R: U], R U R2']" Alg {} "R U2 R' U' R U' R'"

import { Alg } from "https://cdn.cubing.net/js/cubing/alg";
const antiSune = new Alg("[[R: U], R U R2']");
const niklas = new Alg("[R, [U': L']] U'");

const jPerm = antiSune.concat(niklas);
jPerm.log();
jPerm.expand().log();
jPerm.expand().simplify({cancel: true}).log();
Alg {} "[[R: U], R U R2'] [R, [U': L']] U'" Alg {} "R U R' R U R2' R U' R' R2 U' R' R U' L' U R' U' L U U'" Alg {} "R U2 R' U' R U2' L' U R' U' L"

.expand() and .experimentalSimplify() can also take options:

import { Alg } from "https://cdn.cubing.net/js/cubing/alg";

const oll = new Alg("[F: [R, U]]");
oll.expand({depth: 1}).log();
Alg {} "F [R, U] F'"