Created
February 24, 2017 18:27
-
-
Save vpsk-zz/a5e6630dd17efd4b186a32a5142b9cc2 to your computer and use it in GitHub Desktop.
ransomeNote Machine Test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myFunction = function(newsPaper, ransomNote) { | |
if (ransomNote.length > newsPaper.length) { | |
return false; | |
} | |
var ransomNoteArr = ransomNote.trim().split((/[. ,]+/)); | |
var newsPaper = newsPaper.split((/[. ,]+/)); | |
var i = 0; | |
for(i=0; i < ransomNoteArr.length; i++){ | |
if(newsPaper.indexOf(ransomNoteArr[i]) > 0){ | |
newsPaper.splice(newsPaper.indexOf(ransomNoteArr[i]),1) | |
}else{ | |
break; | |
} | |
} | |
if(i === ransomNoteArr.length) { | |
return true; | |
}else { | |
return false; | |
} | |
}; | |
var x = "You have kidnapped your neighbour's dog and intend to send a ransom note to him.You write the ransom note from today's newspaper cutting out words."; | |
var y = " note "; | |
myFunction(x,y); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment