← todo

browserify test, finding out how does it work

38d38f8a8371231783362764c8c4dc77d508f237 · ovidiucs · Apr 15, 2014 03:53

+70 −2 · 3 files changed

  • .gitignore +2 −0
  • app/bundle.js +63 −1
  • app/javascript-test.js +5 −1
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..04c1747
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+package.json
+node_modules/
diff --git a/app/bundle.js b/app/bundle.js
index 88174d3..4941e21 100644
--- a/app/bundle.js
+++ b/app/bundle.js
@@ -1,5 +1,67 @@
 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
 //javascript-test.js
 
-console.log("Hallo");
+var unique = require('uniq');
+
+var data = [1, 2, 2, 3, 4, 5, 5, 5, 6];
+
+console.log(unique(data));
+},{"uniq":2}],2:[function(require,module,exports){
+"use strict"
+
+function unique_pred(list, compare) {
+  var ptr = 1
+    , len = list.length
+    , a=list[0], b=list[0]
+  for(var i=1; i<len; ++i) {
+    b = a
+    a = list[i]
+    if(compare(a, b)) {
+      if(i === ptr) {
+        ptr++
+        continue
+      }
+      list[ptr++] = a
+    }
+  }
+  list.length = ptr
+  return list
+}
+
+function unique_eq(list) {
+  var ptr = 1
+    , len = list.length
+    , a=list[0], b = list[0]
+  for(var i=1; i<len; ++i, b=a) {
+    b = a
+    a = list[i]
+    if(a !== b) {
+      if(i === ptr) {
+        ptr++
+        continue
+      }
+      list[ptr++] = a
+    }
+  }
+  list.length = ptr
+  return list
+}
+
+function unique(list, compare, sorted) {
+  if(list.length === 0) {
+    return []
+  }
+  if(compare) {
+    if(!sorted) {
+      list.sort(compare)
+    }
+    return unique_pred(list, compare)
+  }
+  if(!sorted) {
+    list.sort()
+  }
+  return unique_eq(list)
+}
+
+module.exports = unique
 },{}]},{},[1])
\ No newline at end of file
diff --git a/app/javascript-test.js b/app/javascript-test.js
index 1f5f479..9519b52 100644
--- a/app/javascript-test.js
+++ b/app/javascript-test.js
@@ -1,3 +1,7 @@
 //javascript-test.js
 
-console.log("Hallo");
\ No newline at end of file
+var unique = require('uniq');
+
+var data = [1, 2, 2, 3, 4, 5, 5, 5, 6];
+
+console.log(unique(data));
\ No newline at end of file