1. Calle Robertsson
  2. Katas

Commits

Calle Robertsson  committed 4d26663

Added and modified stuf.

  • Participants
  • Parent commits 223d62d
  • Branches master

Comments (0)

Files changed (5)

File KarateChop/src/karatechop.coffee

View file
 
 		m =  x + parseInt (y - x) / 2
 
-		#console.log "  x: #{x}, y: #{y}, m: #{m}, ns[m]: #{ns[m]}"
+		console.log "  x: #{x}, y: #{y}, m: #{m}, ns[m]: #{ns[m]}"
 
 		return m if ns[m] == n
 

File StringCalculator/src/calc.coffee

View file
 		else
 			numberArray.reduce (a, b) -> 
 				a + b
-		
-		
-

File StringCalculator/src/calc.js

View file
+// Generated by CoffeeScript 1.6.3
+(function() {
+  alert("foo");
+
+  pritn("apap");
+
+  exports.add = function(numberString) {
+    var i, num, numberArray, separator, _i, _len;
+    if (numberString === '') {
+      return 0;
+    } else {
+      separator = /[\s,]/g;
+      if ((numberString.indexOf('//')) === 0) {
+        separator = numberString[2];
+        numberString = numberString.slice(3);
+      }
+      numberArray = numberString.split(separator);
+      for (i = _i = 0, _len = numberArray.length; _i < _len; i = ++_i) {
+        num = numberArray[i];
+        numberArray[i] = parseInt(numberArray[i]);
+        if (numberArray[i] < 0) {
+          throw new Error("negatives not allowed");
+        }
+        if (numberArray[i] > 1000) {
+          numberArray.splice(i, 1);
+          console.log(numberArray);
+        }
+      }
+      if (numberArray.length === 1) {
+        return numberArray[0];
+      } else {
+        return numberArray.reduce(function(a, b) {
+          return a + b;
+        });
+      }
+    }
+  };
+
+  add("2");
+
+}).call(this);

File StringCalculator/src/useCalc.coffee

View file
+console.log "apa"
+
+Calc = require '../src/calc'
+
+console.log "bepa"
+console.log Calc.add("2\n3")

File StringCalculator/test/calcTest.js

View file
+// Generated by CoffeeScript 1.6.3
+(function() {
+  var Calc, chai;
+
+  chai = require('chai');
+
+  chai.should();
+
+  Calc = require('../src/calc');
+
+  describe('Calc add', function() {
+    it('should return 0 for empty input', function() {
+      return (Calc.add('')).should.equal(0);
+    });
+    it('should return 4 for "4"', function() {
+      return (Calc.add('4')).should.equal(4);
+    });
+    it('should return 17 for "8\\n9"', function() {
+      return (Calc.add('8\n9')).should.equal(17);
+    });
+    it('should return 99 for "1\\n2,3\\n93"', function() {
+      return (Calc.add('1\n2,3\n93')).should.equal(99);
+    });
+    it('should return 99 for "//|12|3|93"', function() {
+      return (Calc.add('//|1|2|3|93')).should.equal(99);
+    });
+    it('should throw on negative numbers', function() {
+      return (function() {
+        return Calc.add('1,2,-3,4');
+      }).should["throw"]("negatives not allowed");
+    });
+    return it('should return ignore values greater than 1000', function() {
+      return (Calc.add('999,1000,1001')).should.equal(1999);
+    });
+  });
+
+}).call(this);