Advertisement
Guest User

Untitled

a guest
Sep 27th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. const answer = (checkWords) => {
  2. const [firstWord, secondWord] = checkWords.split(' ');
  3. if (firstWord.length !== secondWord.length) {
  4. return 0;
  5. }
  6. const sortedFirstWord = [...firstWord].sort();
  7. const sortedSecondWord = [...secondWord].sort();
  8. for (let i = 0; i < firstWord.length; i++) {
  9. if ((sortedFirstWord[i] !== sortedFirstWord[i - 1] && sortedSecondWord[i] === sortedSecondWord[i - 1])
  10. || (sortedFirstWord[i] === sortedSecondWord[i - 1] && sortedSecondWord[i] !== sortedSecondWord[i - 1]))
  11. return 0;
  12. }
  13. return 1;
  14. }
  15.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement