Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: j1n3l0/codewars
base: a63928f868
...
head fork: j1n3l0/codewars
compare: be499b197b
Checking mergeability… Don't worry, you can still create the pull request.
  • 18 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 52 additions and 0 deletions.
  1. +51 −0 test/codewars-test.coffee
  2. +1 −0  test/mocha.opts
View
51 test/codewars-test.coffee
@@ -0,0 +1,51 @@
+expect = require("chai").expect
+
+#
+# http://www.codewars.com/dojo/katas/513fa1d75e4297ba38000003
+describe "flatten an array (of possibly nested arrays)", ->
+ solution = (coll...) ->
+ [].concat (coll.map (x) -> if Array.isArray x then solution x... else x)...
+
+ it "should flatten simple arrays", ->
+ expect([1, 2, 3, 4, 5, 6, 7]).to.eql(solution 1, [2, 3], 4, 5, [6, [7]])
+
+#
+# http://www.codewars.com/dojo/katas/5174a4c0f2769dd8b1000003
+describe "sort an array", ->
+ solution = (coll) ->
+ if coll is null or coll.length is 0 then [] else coll.sort (a,b) -> a > b
+
+ it "should return [] for null", ->
+ expect([]).to.eql(solution null)
+
+ it "should return [] for []", ->
+ expect([]).to.eql(solution [])
+
+ it "should return sorted arrays", ->
+ expect([1,2,3,4,5]).to.eql(solution [2,4,5,1,3])
+
+#
+# http://www.codewars.com/dojo/katas/513e08acc600c94f01000001
+# Useful information available: http://www.statman.info/conversions/hexadecimal.html
+describe "RGB To Hex Conversion", ->
+ solution = (r,g,b) ->
+ hex_value = "0123456789ABCDEF"
+ [r,g,b]
+ .map((n) -> Math.min 255, Math.max(0, n))
+ .map((n) -> hex_value[Math.floor(n/16)] + hex_value[n%16])
+ .join("")
+
+ it "should convert max decimal to hexadecimal", ->
+ expect(solution 255, 255, 255).to.eql("FFFFFF")
+
+ it "should convert min decimal to hexadecimal", ->
+ expect(solution 0,0,0).to.eql("000000")
+
+ it "should round down numbers > max = 255", ->
+ expect(solution 255, 255, 300).to.eq("FFFFFF")
+
+ it "should round up numbers < min = 0", ->
+ expect(solution 0,0,-20).to.eql("000000")
+
+ it "should convert all valid decimal to hexadecimal numbers", ->
+ expect(solution 148, 0, 211).to.eql("9400D3")
View
1  test/mocha.opts
@@ -0,0 +1 @@
+ --compilers coffee:coffee-script

No commit comments for this range

Something went wrong with that request. Please try again.