Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Changing representation of operations to a string where the first cha…

…racter is the operation type
  • Loading branch information...
commit fafde5034c4a3260fe119629b9d3816ad971ee1e 1 parent 30e05ac
@fitzgen authored
Showing with 16 additions and 5 deletions.
  1. +16 −5 operations.js
View
21 operations.js
@@ -14,23 +14,34 @@ define(function () {
// Simple change constructors.
function insert (chars) {
- return ["insert", chars];
+ return "i" + chars;
}
function del (chars) {
- return ["delete", chars];
+ return "d" + chars;
}
function retain (n) {
- return ["retain", n];
+ return "r" + String(n);
}
function type (change) {
- return change[0];
+ switch ( change.charAt(0) ) {
+ case "r":
+ return "retain";
+ case "d":
+ return "delete";
+ case "i":
+ return "insert";
+ default:
+ throw new TypeError("Unknown type of change: ", change);
+ }
}
function val (change) {
- return change[1];
+ return type(change) === "r"
+ ? Number(change.slice(1))
+ : change.slice(1);
}
// We don't want to copy arrays all the time, aren't mutating lists, and
Please sign in to comment.
Something went wrong with that request. Please try again.