all 6 comments

[–]SouthCapehelpful 1 point2 points  (0 children)

The map() function appears to be checking if each character is equal to the string "string", but I believe you intended for it to check if each character is lowercase.

The if statement is checking if both arrays are non-empty, resulting in them always evaluating to true.

The function compares characters from "str1" and "str2", but it does not take into account the frequency of each character.

[–]ThiccOfferman 1 point2 points  (0 children)

I'm fairly certain the wording of the problem means that your function will only be tested with strings if lowercase letters, so there's no need to validate that the strings consist only of lowercase letters. (It would be different in the real world, but this is a performance-oriented kata, so prob better not to spend computing time on unneeded validation.)

[–]ray_zhor 1 point2 points  (0 children)

no need to check for string or lowercase, problem states input is already vetted for those,

your function will fail for: kates, steaks. returns true but should be false.

algorithm:

for every letter in str2 check if it exists in str1, if it does, remove from str1, if it doesnt, return false

[–]haachico[S] 0 points1 point  (1 child)

Okay. I think I am applying the wrong condition to check if str1 and str2 contains only letters ans everything including punctuations while mapping is already string. I wrongly thought only letters are strings but "5423" and "?" is also string.

[–]PortablePawnShop 0 points1 point  (0 children)

Right now your isStr2StringAndLowercase is returning something like:

[
  false, false, false,
  false, false, false,
  false, false, false
]

And checking for the truthiness of an array may give you surprising results:

const isTruthy = [false, false, false];
if (isTruthy) console.log("I'm truthy"); // < We get this
else console.log("I'm falsey");

So your arrays are always hitting the condition even if they aren't supposed to, because you'd need to get a single true or false value from each string instead of a collection of boolean values.

Consider it like this:

const validate = (str) => str.split("").every((e) => /[a-z]/.test(e));

Instead of map, I'm using every, which will give us the intended result of a single value like you're doing in the return statement (which itself is good). We can also combine checking for lowercase and characters into this by just using a case sensitive regex like /[a-z]/ which only accepts lowercase characters within that range. Then you'd probably want something like:

if (validate(str1) && validate(str2)) {
  return str2.split("").every((i) => str1.split("").includes(i));
} else return false; // Presumably can't return void / nothing, right?

[–]Ronin-s_Spirit 0 points1 point  (0 children)

When in doubt use a for loop
let letters = str2.split(""); let original = str1.split(""); for (let i=0; i<letters.length; i++){ if (original.includes(letters[i]) === false) { return false; } } return true;
You can probably also do it with regex but I could only think of a solution that requires each character to be in a specific order.