JSFiddle - React, Tailwind, and code Playground
by Bharath Kumaar
JavaScript
let word1 = 'PERMMMIT',
word2 = 'TEERPIONMMM';
let checkIfWordCanBeFormedFromAnother = (word1, word2) => {
let word1Characters = word1.split(''),
word2Characters = word2.split('');
word1Characters.filter(word1character => word2Characters.indexOf(word1character) === -1);
console.log(word1Characters)
/* for ( let character1 of word1Characters ) {
let index = word2Characters.indexOf(character1);
if( index === -1)
return false;
else
word2Characters [ index ] = '';
}
return true; */
}
console.log(checkIfWordCanBeFormedFromAnother(word1, word2));