Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bonfire: Mutations - wrong test case #5919

Closed
sardware opened this issue Jan 6, 2016 · 1 comment
Closed

Bonfire: Mutations - wrong test case #5919

sardware opened this issue Jan 6, 2016 · 1 comment

Comments

@sardware
Copy link

sardware commented Jan 6, 2016

Challenge Bonfire: Mutations has an issue.
User Agent is: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36.
Please describe how to reproduce this issue, and include links to screenshots if possible.

My code:

function sortString(str){
  return str.toLowerCase().split('').sort().join('');
}

function countSorted(str,char){
  var c = 0;
  var pos = str.indexOf(char);
  while (str[pos++] === char) c++;
  return c;
}

function mutation(arr) {
  var lastChar = '';
  var s1 = sortString(arr[0]);
  var s2 = sortString(arr[1]);
  var l2 = s2.length;
  var res = true;
  for (var i=0; i < l2; i++){
    if (s2[i] === lastChar) continue;
    lastChar = s2[i];
    if (countSorted(s1,lastChar) < countSorted(s2,lastChar)){
      res = false;
      break;
    }
  }
  return res;
}

mutation(["Mary", "Aarmy"])

The testcase is mutation(["Mary", "Aarmy"]), the system says it should return true because it doesn't care about only one 'a' in the first string, but i think it should return false due to the problem description.

@SaintPeter
Copy link
Member

Return true if the string in the first element of the array contains all of the letters of the string in the second element of the array.

It says "all of the letters of the string", it doesn't say anything about quantity, just presence. This is reinforced by all of the test cases which support that notion. This is not an error, this is the definition.

You may want to try a solution that uses indexOf to search one string for the presence of another. Your current solution does not conform well to the problem as described.

Happy Coding!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants