Skip to content

Commit

Permalink
feat: add support for multi-dimensional arrays for array.add
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenrui committed Mar 23, 2024
1 parent ab3682f commit da36e44
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/helpers/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,21 @@ export class MiniArray extends Array {
const values = flattenArgs(args)
const flattenArray = this.deepFlat()
const toAddValues = values.filter((value) => !flattenArray.includes(value))

deepRemove(this, values)
this.push(...toAddValues)

return this
}

add(value) {
let index = this.indexOf(value)
if (index !== -1) return this
add(...args) {
const flattenArray = this.deepFlat()
const toAddValues = flattenArgs(args).filter(
(value) => !flattenArray.includes(value)
)

this.push(...toAddValues)

this.push(value)
return this
}

Expand Down

0 comments on commit da36e44

Please sign in to comment.