Skip to main content
Module

x/rambda/source/_internals/set.js

Faster and smaller alternative to Ramda
Go to Latest
File
import {type as typeMethod} from '../type'import {_indexOf} from '../equals'
export class _Set { constructor() { this.set = new Set() this.items = {} } checkUniqueness(item) { const type = typeMethod(item) if (['Null', 'Undefined', 'NaN'].includes(type)) { if (type in this.items) { return false } this.items[type] = true return true } if (!['Object', 'Array'].includes(type)) { const prevSize = this.set.size this.set.add(item) return this.set.size !== prevSize }
if (!(type in this.items)) { this.items[type] = [item] return true }
if (_indexOf(item, this.items[type]) === -1) { this.items[type].push(item) return true } return false }}