I am playing with my friends on internet
we ask each other to say ( name, or animal, or inanimate) begins with a particular letter
So I am thinking about building a page to help me in training about this game
This is an php code for example:
function getNamesByChars($chars,$type='name'){
$names=array(
'd'=>'Dan',
'j'=>'John',
);
$animals=array(
'd'=>'Dog',
'j'=>'Jar',
);
$chars=explode(' ',$chars);
foreach($chars as $char){
//if it a name
if($type=='name')
$results.=$names[$char];
//if it animal
elseif($type=='animal')
$results.=$animals[$char];
}
}
getNamesByChars('j d','animal');
//results (Jar dog)
the problem here that i need to make this page faster as much as possible
PHP requires loading the page
i Think javascript is the faster way
but i am very beginner in javascript so i can't build this function
Any help in building this function in javascript?