lundi 29 février 2016

Is this an elegant solution?

The problem is not complicated. Log randomly a name from an array of names.

My solution comes as this.

var names = [ 'nick', 'rock', 'danieel' ];
function randPicker(names) {
    var randNum = Math.floor((Math.random() * 10));
    var name = randNum <= (names.length - 1) ? console.log(names[randNum]) : randPicker(arguments[0]); 
};

It seems to me that this code is not that beautiful, because im quite sure that there are better ways that perform much faster. Is that true?




Aucun commentaire:

Enregistrer un commentaire