Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

compute-anagram-hash

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compute-anagram-hash - npm Package Compare versions

Comparing version 0.0.0 to 0.0.1

52

lib/index.js

@@ -418,5 +418,57 @@ /**

/**
* METHOD: copy( [keys] )
* Returns a copy of the hash table.
*
* @param {String[]} [keys] - list of keys to be copied
* @returns {AnagramHash} new AnagramHash instance
*/
AnagramHash.prototype.copy = function( arr ) {
var nargs = arguments.length,
hash = this._hash,
nhash,
nlist,
copy,
list,
keys,
key,
len,
N, i, j;
if ( nargs ) {
if ( !isStringArray( arr ) ) {
throw new TypeError( 'copy()::invalid input argument. Keys must be a primitive string array. Value: `' + arr + '`.' );
}
keys = arr;
} else {
keys = Object.keys( hash );
}
len = keys.length;
// Create a (n)ew hash table:
copy = new AnagramHash();
nhash = copy._hash;
// Loop through each key...
for ( i = 0; i < len; i++ ) {
key = keys[ i ];
if ( !hash.hasOwnProperty( key ) ) {
continue;
}
list = hash[ key ];
N = list.length;
// Copy the anagrams to the new hash table...
nlist = new Array( N );
for ( j = 0; j < N; j++ ) {
nlist[ j ] = list[ j ];
}
nhash[ key ] = nlist;
}
return copy;
}; // end METHOD copy()
// EXPORTS //
module.exports = AnagramHash;

2

package.json
{
"name": "compute-anagram-hash",
"version": "0.0.0",
"version": "0.0.1",
"description": "Anagram hash table.",

@@ -5,0 +5,0 @@ "author": {

@@ -159,4 +159,25 @@ Anagram Hash

#### hash.copy( [keys] )
Copies an [anagram](http://en.wikipedia.org/wiki/Anagram) hash table to a new hash table instance.
``` javascript
var copy = hash.copy();
var list = copy.get( 'abt', true );
// returns ['bat','tab']
```
To only copy specific __keys__ to a new hash table, provide a __keys__ `array`.
``` javascript
var copy = hash.copy( ['beep'] );
var keys = copy.keys();
// returns ['beep']
```
## Examples

@@ -163,0 +184,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc