utils.js
À propos du fichier
- Type de fichier
- Fichier JS de 2 Ko (text/plain)
- Confidentialité
- Fichier public, envoyé le 9 avril 2018 à 07:42, depuis l'adresse IP 154.120.x.x (MG)
- Sécurité
- Ne contient aucun Virus ou Malware connus - Dernière vérification: 3 jours
- Statistiques
- La présente page de téléchargement a été vue 766 fois depuis l'envoi du fichier
- Page de téléchargement
-
Aperçu du fichier
'use strict';
var ObjectUtils = {
exists : function(object){
return typeof object != 'undefined' && object != null;
},
notExists : function(object){
return !ObjectUtils.exists(object);
}
};
var ArrayUtils = {
isArray : function(object){
return ObjectUtils.exists(object) &&
object instanceof Array;
},
isNotArray : function(object){
return !ArrayUtils.isArray(object);
},
isEmpty : function(array){
return ArrayUtils.isNotArray(array) || array.length == 0;
},
isNotEmpty : function(array){
return !ArrayUtils.isEmpty(array);
},
removeItem : function(array, index){
if (ArrayUtils.isEmpty(array))
return array;
var length = array.length;
var reducedArray = [];
for (var i = 0; i < length; i++){
if (i != index)
reducedArray.push(array[i]);
}
return reducedArray;
},
shuffle : function(array, randomizedIndexArray){
var clonedArray = array;
var shuffledArray = [];
var hasRandomizeIndexArray = ArrayUtils.isArray(randomizedIndexArray);
while (clonedArray.length > 0){
var randomIndex = Math.floor(Math.random() * clonedArray.length);
if (hasRandomizeIndexArray)
randomizedIndexArray.push(randomIndex);
shuffledArray.push(clonedArray[randomIndex]);
clonedArray = ArrayUtils.removeItem(clonedArray, randomIndex);
}
return shuffledArray;
},
insert : function(array, item, index){
var insertedArray = [];
if (ArrayUtils.isEmpty(array)){
insertedArray.push(item);
return insertedArray;
}
var length = array.length;
if (index >= length){
for (var i = 0; i < length; i++)
insertedArray.push(array[i]);
insertedArray.push(item);
return insertedArray;
}
for (var i = 0; i < index; i++)
insertedArray.push(array[i]);
insertedArray.push(item);
for (var i = index;i < length; i++)
insertedArray.push(array[i]);
return insertedArray;
}
};
var StringUtils = {
isEmpty : function(object){
return !ObjectUtils.exists(object) || object.length == 0;
}
};
Partager le fichier utils.js sur le Web et les réseaux sociaux:
Télécharger le fichier utils.js