Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const answer = (checkWords) => {
- const [firstWord, secondWord] = checkWords.split(' ');
- if (firstWord.length !== secondWord.length) {
- return 0;
- }
- const sortedFirstWord = [...firstWord].sort();
- const sortedSecondWord = [...secondWord].sort();
- for (let i = 0; i < firstWord.length; i++) {
- if ((sortedFirstWord[i] !== sortedFirstWord[i - 1] && sortedSecondWord[i] === sortedSecondWord[i - 1])
- || (sortedFirstWord[i] === sortedSecondWord[i - 1] && sortedSecondWord[i] !== sortedSecondWord[i - 1]))
- return 0;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement