Ad
  • Custom User Avatar

    Your code is counting number of unique elements in the input. For the case of input "aaabbb", your function computes an uniqueArr to be of length 0. And returns true, while the expected answer is false.

    Instead, you must determine whether ONLY one element occcurs ODD number of times.

    • For the case of input "aaabbb", your logic would compute 2 (both a and b occur odd number of times). In this case, since it is more than one, your function should return false.
    • For the case of input "aaabbbb", your logic would compute 1 (only a occurs odd number of times). And therefore function should return true. (bbaaabb or abbabbawould be valid palindromes).

    I hope this helps!

  • Default User Avatar

    try your function with e.g. "aaabbb"

  • Custom User Avatar

    I don't understand how adamm which would become mmada is a palindrome ?

  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Default User Avatar

    I'm almost siting all night, trying to solve this task. If you are so smart find error in my solution! Why it doesn't pass random test?
    function permuteAPalindrome (input) {
    let arr = input.split('');
    const uniqueArr = [];

    for (let i = 0; i < arr.length; i++) {
    if (arr.indexOf(arr[i]) === arr.lastIndexOf(arr[i])) {
    uniqueArr.push(arr[i]);
    }
    }
    if( (uniqueArr.length < 1) || (uniqueArr.length === 1) ) return true;
    else if (uniqueArr.length > 1) return false;
    }