Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const prepareString = (text) => text.split(' ').join('').split('');
- const flames = (name1, name2) => {
- const flames = ['FRIENDS', 'LOVERS', 'ANGRY', 'MARRIED', 'ENEMIES', 'SOULMATES'];
- const name1arr = (name1.length < name2.length) ? prepareString(name1) : prepareString(name2);
- let nameToCompare = (name1.length < name2.length) ? name2 : name1;
- const matches = [];
- name1arr.forEach(x => {
- const indexMatch = nameToCompare.indexOf(x);
- if (indexMatch > -1) {
- matches.push(x);
- nameToCompare = nameToCompare.replace(x, '$');
- }
- });
- return {
- matches,
- flames: flames[(matches.length-1) % 6]
- };
- }
- const result = flames('m a r k h u g h n e ri', 'm a r k h u g h n e r i')
- console.log(result);
- // { matches: [ 'm', 'a', 'r', 'k', 'h', 'u', 'g', 'h', 'n', 'e', 'r', 'i' ],
- // flames: 'SOULMATES' }
Add Comment
Please, Sign In to add comment