Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isPossible (str1, str2) {
- var chars1 = str1.split('');
- var chars2 = str2.split('');
- var length = chars2.length;
- while (length--) {
- var pos = chars1.indexOf(chars2[length]);
- if (chars2[length] !== ' ') {
- if (-1 !== pos) {
- //Char exists in source string - remove it
- chars1.splice(pos, 1);
- } else {
- return false;
- }
- }
- //Char exists in result string - remove it
- chars2.splice(length, 1);
- }
- return true;
- }
- console.log(isPossible('clockwise', 'is clock'));//->true
- console.log(isPossible('clockwise', 'is ccc'));//->false
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement