Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
there will always be only one or zero occurances of '#' so there will only ever be two strings
This is clean and simple.
Random tests matrix size clamped at 8
Number of hard tests with size of 10 reduced to 2.
Pro tip: don't waste your energy trying to up the quality of codewars posts
Bad practice because:
Holly ....
So many functions
Has description conflict.
@JustifiedFlaw ..
I added those test cases to python. If someone is willing to do the same for JavaScript it would be nice.
In a real implementation you would just handle those cases seperately. With an empty alphabet always return empty output. With an alphabet of one character return the count of the character (or something similar).
Oh it's Huffman encoding that is like that, I understand now.
As I've already written, the issue is not in the test case. Your function should return
null
in that case. There is no general way to implement Huffman encoding for less than 2 letters in an alphabet.0
or1
is assigned by the path you take and if no path is taken the code is empty.The test is "singleton frequency encode". I get "Expected: null, instead got: ''". The input is encode([['a', 1]], "");
Can you give the title of the test case? I can't find the behavior in the test cases.
One thing that may seem a bit odd is, that once the frequencies have less than 2 elements it always returns
null
(Nothing
in Haskell). But it is in fact the most logical way. It's trival with zero elements in the alphabet (of course one could always return the empty string) but with one element in the alphabet the encoding is also an empty string (for all inputs with that character).Javascript
Loading more items...