Skip to content

Instantly share code, notes, and snippets.

View jimmybatuhan's full-sized avatar
🎯
Focusing

plumeray jimmybatuhan

🎯
Focusing
View GitHub Profile
@jimmybatuhan
jimmybatuhan / matcher.js
Created August 22, 2019 03:22
Compare a name to a collection of names, returns the percentage of each names
let name = 'James Bond';
let names = [
'Goerge Mallory',
'Marie Curry',
'Tom Yorke',
'Jimmy Wales',
'James Blonde',
'j@M3$ b0ND',
];
let handlebar = function(string, handlers){
if(string.match(/({{).*?(}})/g).length){
Object.keys(handlers).forEach( key => { string = string.replace(new RegExp("({{)"+key+"(}})"), handlers[key]); });
};
return string;
};
module.exports = handlebar();