These are chat archives for Codewars/codewars.com/kata-solving-help
Stuck on a kata? Ask questions here! Please keep spoilers to a minimum, though, but don't expect a spoiler free environment either.
function twoSort(s) {
// sort the vector
// extract the first value
// add *** between each letter
let sorted = s.sort();
console.log(sorted);
let first = sorted.shift();
console.log(first)
return first.split('').join('***');
}
Random tests
Testing for MadeSafeCoin,Steem,Ripple
Log
[ 'MadeSafeCoin', 'Ripple', 'Steem' ]
MadeSafeCoin
✘ It should work for random inputs too - Expected: 'R***i***p***p***l***e', instead got: 'M***a***d***e***S***a***f***e***C***o***i***n'
Completed in 1ms
public class Kata
{
public static int DuplicateCount(string str)
{
var alphabets = "abcdefghijklmnopqrstuvwxyz123456789".ToCharArray();
int[] nums = new int[alphabets.Length];
var tmp = str.ToLower().ToCharArray();
if (!string.IsNullOrEmpty(str))
{
foreach (var item in tmp)
{
for (int i = 0; i < alphabets.Length; i++)
{
if (item == alphabets[i])
{
nums[i] += 1;
}
}
}
return nums.Count(num => num > 1);
}
else {
return 0;
}
}
public void ShowStr(string str)
{
Console.WriteLine(DuplicateCount(str));
}
}
RandomTests
✔ 1 assertion passed
✘ Expected: 8
But was: 7
Completed in 0.047428ms
shift
.
splice(0, 1)
as well but my random tests keep failing. I'm missing something?
slice(0, 1)
but at a loss on why does it work
thanks for the help, but don't understand very well what you mean by
Many kata authors completely forget that arrays have reference semantics and don't copy them in their random tests.
var random_strings = generateRandomStrings();
var reference_solution = function(str){
....
}
Test.assert_equals(yoursolution(random_strings), reference_solution(random_strings));
yoursolution
changes random_strings
, the reference_solution
will use the changed array.
splice
, random_strings
"lost" "MadeSafeCoin"
. Therefore, the authors reference solution returned "Ripple"
(with stars).
random_strings
didn't contain "MadeSafeCoin"
anymore.
var random_strings = generateRandomStrings();
var reference_solution = function(str){
....
}
Test.assert_equals(yoursolution(makeCopy(random_strings)), reference_solution(random_strings));
// ^^
0
in your alphabet.
String
is enumerable.