Replace instanceof Array checks with Array.isArray
This commit is contained in:
parent
060345e96a
commit
8401a10127
2 changed files with 5 additions and 5 deletions
|
@ -50,7 +50,7 @@ var random = { // eslint-disable-line no-unused-vars
|
||||||
return Math.exp(this.float() * Math.log(limit))
|
return Math.exp(this.float() * Math.log(limit))
|
||||||
},
|
},
|
||||||
item: function (list) {
|
item: function (list) {
|
||||||
if (!(list instanceof Array || (list !== undefined && typeof list !== 'string' && list.hasOwnProperty('length')))) {
|
if (!(Array.isArray(list) || (list !== undefined && typeof list !== 'string' && list.hasOwnProperty('length')))) {
|
||||||
logger.traceback()
|
logger.traceback()
|
||||||
throw new TypeError('this.item() received a non array type: \'' + list + '\'')
|
throw new TypeError('this.item() received a non array type: \'' + list + '\'')
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ var random = { // eslint-disable-line no-unused-vars
|
||||||
if (typeof obj === 'function') {
|
if (typeof obj === 'function') {
|
||||||
return obj()
|
return obj()
|
||||||
}
|
}
|
||||||
if (obj instanceof Array) {
|
if (Array.isArray(obj)) {
|
||||||
return this.pick(this.item(obj))
|
return this.pick(this.item(obj))
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
|
@ -86,7 +86,7 @@ var random = { // eslint-disable-line no-unused-vars
|
||||||
return this.number(limit) === 1
|
return this.number(limit) === 1
|
||||||
},
|
},
|
||||||
choose: function (list, flat) {
|
choose: function (list, flat) {
|
||||||
if (!(list instanceof Array)) {
|
if (!(Array.isArray(list))) {
|
||||||
logger.traceback()
|
logger.traceback()
|
||||||
throw new TypeError('random.choose() received a non-array type: \'' + list + '\'')
|
throw new TypeError('random.choose() received a non-array type: \'' + list + '\'')
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ var random = { // eslint-disable-line no-unused-vars
|
||||||
return newArray
|
return newArray
|
||||||
},
|
},
|
||||||
subset: function (list, limit) {
|
subset: function (list, limit) {
|
||||||
if (!(list instanceof Array)) {
|
if (!(Array.isArray(list))) {
|
||||||
logger.traceback()
|
logger.traceback()
|
||||||
throw new TypeError('random.subset() received a non-array type: \'' + list + '\'')
|
throw new TypeError('random.subset() received a non-array type: \'' + list + '\'')
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ utils.block = {
|
||||||
if (typeof (item) === 'string') {
|
if (typeof (item) === 'string') {
|
||||||
return item
|
return item
|
||||||
}
|
}
|
||||||
if (item instanceof (Array)) {
|
if (Array.isArray(item)) {
|
||||||
let s = ''
|
let s = ''
|
||||||
for (let i = 0; i < item.length; i++) {
|
for (let i = 0; i < item.length; i++) {
|
||||||
s += deeper(item[i])
|
s += deeper(item[i])
|
||||||
|
|
Loading…
Reference in a new issue