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
// flames.js | |
// FLAMES game. Algorithm can be found here: http://flamesgame.appspot.com/algorithm | |
const getFlame = (name1, name2) => | |
name1.toLowerCase().split(''). // take all characters in "name1", to compare | |
filter(c => name2.toLowerCase().includes(c)). // keep only characters (in "name1") also found in "name2" | |
reduce((result, c) => [ | |
result[0].replace(new RegExp(`${c}`, 'g'), ''), // replace common characters in "name1" | |
result[1].replace(new RegExp(`${c}`, 'g'), '') // replace common characters in "name2" | |
], [name1.toLowerCase(), name2.toLowerCase()]). |