Skip to content

Instantly share code, notes, and snippets.

View ola-sumbo's full-sized avatar

ola-sumbo ola-sumbo

View GitHub Profile
@vicsstar
vicsstar / flames.js
Last active May 21, 2022 13:40
FLAMES game, written in JavaScript - I liked the logic behind the game and wanted to represent it in code
// 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()]).