Amélioration de la perf de ma fonction
Hello a tous,
j'ai fait une petite fonction qui permet de récupérer des titres sur l'api wiki de façon aléatoire.
Je me tourne vers vous car certain titres que je récupère ressemble a ceci "145" ou "21".
Ce sont des nombre de type string.
J'ai dont ajouté à ma fonction une condition pour ne garder que ce qui est NaN et de se relancer dans le cas échéant.
Pouvez vous me dire si il y a une méthode plus rapide (en terme de performance) pour faire ce tri et passer a un autre titre dans le cas échéant?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
var getTitle = function(){
var dataToSend = '?action=query'+ '&' + 'redirects=' + "" + '&' + 'list=' + "random" + '&' + 'rnnamespace=' + "0";
//We call the connect function and add two parameters (Url of Api and the callback function)
connect('https://en.wikiquote.org/w/api.php'+dataToSend, function(response){
var title = response.query.random[0].title;
//Check if the title is a string and not a numeric string like "152"
if(isNaN(title)){
console.log(title);
return title;
}
//If a numeric string reload the function
getTitle();
}, function(error){
console.log(error);
});
}; |
Merci pour vos conseils