extra-array
Advanced tools
Comparing version 4.0.127 to 4.0.128
214
index.js
@@ -551,42 +551,21 @@ 'use strict'; | ||
} | ||
function take(x, n = 1) { | ||
return x.slice(0, n); | ||
function hasPrefix(x, y, fc = null, fm = null) { | ||
var Y = y.length; | ||
return Y === 0 || compare(x.slice(0, Y), y, fc, fm) === 0; | ||
} | ||
function takeRight(x, n = 1) { | ||
return x.slice(x.length - n); | ||
function hasSuffix(x, y, fc = null, fm = null) { | ||
var Y = y.length; | ||
return Y === 0 || compare(x.slice(-Y), y, fc, fm) === 0; | ||
} | ||
function takeWhile(x, ft) { | ||
return x.slice(0, scanWhile(x, ft)); | ||
function hasInfix(x, y, fc = null, fm = null) { | ||
return searchInfix(x, y, fc, fm) >= 0; | ||
} | ||
function takeWhileRight(x, ft) { | ||
return x.slice(scanWhileRight(x, ft)); | ||
function hasSubsequence(x, y, fc = null, fm = null) { | ||
return searchSubsequence(x, y, fc, fm) >= 0; | ||
} | ||
function drop(x, n = 1) { | ||
return x.slice(n); | ||
function hasPermutation(x, y, fc = null, fm = null) { | ||
var x1 = fm ? x.map(fm) : x.slice(); | ||
var y1 = fm ? y.map(fm) : y.slice(); | ||
return hasSubsequence(x1.sort(), y1.sort(), fc, fm); | ||
} | ||
function dropRight(x, n = 1) { | ||
return x.slice(0, x.length - n); | ||
} | ||
function dropWhile(x, ft) { | ||
return x.slice(scanWhile(x, ft)); | ||
} | ||
function dropWhileRight(x, ft) { | ||
return x.slice(0, scanWhileRight(x, ft)); | ||
} | ||
function count(x, ft) { | ||
var i = -1, a = 0; | ||
for (var v of x) | ||
if (ft(v, ++i, x)) | ||
++a; | ||
return a; | ||
} | ||
function countEach(x, fm = null) { | ||
var fm = fm || IDENTITY; | ||
var i = -1, a = new Map(); | ||
for (var v of x) { | ||
var w = fm(v, ++i, x); | ||
a.set(w, (a.get(w) || 0) + 1); | ||
} | ||
return a; | ||
} | ||
function prefixes(x, n = -1) { | ||
@@ -694,2 +673,55 @@ return [...iprefixes(x, n)]; | ||
} | ||
function searchInfix(x, y, fc = null, fm = null) { | ||
var fc = fc || COMPARE; | ||
var fm = fm || IDENTITY; | ||
var X = x.length, Y = y.length; | ||
for (var i = 0; i <= X - Y; ++i) | ||
if (isInfixAt(x, y, i, fc, fm)) | ||
return i; | ||
return -1; | ||
} | ||
function searchInfixRight(x, y, fc = null, fm = null) { | ||
var fc = fc || COMPARE; | ||
var fm = fm || IDENTITY; | ||
var X = x.length, Y = y.length; | ||
for (var i = X - Y; i >= 0; --i) | ||
if (isInfixAt(x, y, i, fc, fm)) | ||
return i; | ||
return -1; | ||
} | ||
function searchInfixAll(x, y, fc = null, fm = null) { | ||
var fc = fc || COMPARE; | ||
var fm = fm || IDENTITY; | ||
var X = x.length, Y = y.length, a = []; | ||
for (var i = 0; i <= X - Y; ++i) | ||
if (isInfixAt(x, y, i, fc, fm)) | ||
a.push(i); | ||
return a; | ||
} | ||
function isInfixAt(x, y, i, fc, fm) { | ||
var Y = y.length; | ||
for (var j = 0; j < Y; ++j) { | ||
var wx = fm(x[i + j], i + j, x); | ||
var wy = fm(y[j], j, y); | ||
if (fc(wx, wy) !== 0) | ||
return false; | ||
} | ||
return true; | ||
} | ||
function searchSubsequence(x, y, fc = null, fm = null) { | ||
var fc = fc || COMPARE; | ||
var fm = fm || IDENTITY; | ||
var y1 = [...y].map(fm), Y = y1.length; | ||
var a = -1, i = -1, j = 0; | ||
for (var vx of x) { | ||
var wx = fm(vx, ++i, x); | ||
if (fc(wx, y1[j]) !== 0) | ||
continue; | ||
if (a < 0) | ||
a = i; | ||
if (++j >= Y) | ||
return a; | ||
} | ||
return -1; | ||
} | ||
function randomValue(x, fr = Math.random) { | ||
@@ -767,2 +799,42 @@ var i = Math.floor(fr() * x.length); | ||
} | ||
function take(x, n = 1) { | ||
return x.slice(0, n); | ||
} | ||
function takeRight(x, n = 1) { | ||
return x.slice(x.length - n); | ||
} | ||
function takeWhile(x, ft) { | ||
return x.slice(0, scanWhile(x, ft)); | ||
} | ||
function takeWhileRight(x, ft) { | ||
return x.slice(scanWhileRight(x, ft)); | ||
} | ||
function drop(x, n = 1) { | ||
return x.slice(n); | ||
} | ||
function dropRight(x, n = 1) { | ||
return x.slice(0, x.length - n); | ||
} | ||
function dropWhile(x, ft) { | ||
return x.slice(scanWhile(x, ft)); | ||
} | ||
function dropWhileRight(x, ft) { | ||
return x.slice(0, scanWhileRight(x, ft)); | ||
} | ||
function count(x, ft) { | ||
var i = -1, a = 0; | ||
for (var v of x) | ||
if (ft(v, ++i, x)) | ||
++a; | ||
return a; | ||
} | ||
function countEach(x, fm = null) { | ||
var fm = fm || IDENTITY; | ||
var i = -1, a = new Map(); | ||
for (var v of x) { | ||
var w = fm(v, ++i, x); | ||
a.set(w, (a.get(w) || 0) + 1); | ||
} | ||
return a; | ||
} | ||
function indexOf(x, v, i = 0) { | ||
@@ -824,74 +896,2 @@ return x.indexOf(v, i); | ||
} | ||
function searchInfix(x, y, fc = null, fm = null) { | ||
var fc = fc || COMPARE; | ||
var fm = fm || IDENTITY; | ||
var X = x.length, Y = y.length; | ||
for (var i = 0; i <= X - Y; ++i) | ||
if (isInfixAt(x, y, i, fc, fm)) | ||
return i; | ||
return -1; | ||
} | ||
function searchInfixRight(x, y, fc = null, fm = null) { | ||
var fc = fc || COMPARE; | ||
var fm = fm || IDENTITY; | ||
var X = x.length, Y = y.length; | ||
for (var i = X - Y; i >= 0; --i) | ||
if (isInfixAt(x, y, i, fc, fm)) | ||
return i; | ||
return -1; | ||
} | ||
function searchInfixAll(x, y, fc = null, fm = null) { | ||
var fc = fc || COMPARE; | ||
var fm = fm || IDENTITY; | ||
var X = x.length, Y = y.length, a = []; | ||
for (var i = 0; i <= X - Y; ++i) | ||
if (isInfixAt(x, y, i, fc, fm)) | ||
a.push(i); | ||
return a; | ||
} | ||
function isInfixAt(x, y, i, fc, fm) { | ||
var Y = y.length; | ||
for (var j = 0; j < Y; ++j) { | ||
var wx = fm(x[i + j], i + j, x); | ||
var wy = fm(y[j], j, y); | ||
if (fc(wx, wy) !== 0) | ||
return false; | ||
} | ||
return true; | ||
} | ||
function searchSubsequence(x, y, fc = null, fm = null) { | ||
var fc = fc || COMPARE; | ||
var fm = fm || IDENTITY; | ||
var y1 = [...y].map(fm), Y = y1.length; | ||
var a = -1, i = -1, j = 0; | ||
for (var vx of x) { | ||
var wx = fm(vx, ++i, x); | ||
if (fc(wx, y1[j]) !== 0) | ||
continue; | ||
if (a < 0) | ||
a = i; | ||
if (++j >= Y) | ||
return a; | ||
} | ||
return -1; | ||
} | ||
function hasPrefix(x, y, fc = null, fm = null) { | ||
var Y = y.length; | ||
return Y === 0 || compare(x.slice(0, Y), y, fc, fm) === 0; | ||
} | ||
function hasSuffix(x, y, fc = null, fm = null) { | ||
var Y = y.length; | ||
return Y === 0 || compare(x.slice(-Y), y, fc, fm) === 0; | ||
} | ||
function hasInfix(x, y, fc = null, fm = null) { | ||
return searchInfix(x, y, fc, fm) >= 0; | ||
} | ||
function hasSubsequence(x, y, fc = null, fm = null) { | ||
return searchSubsequence(x, y, fc, fm) >= 0; | ||
} | ||
function hasPermutation(x, y, fc = null, fm = null) { | ||
var x1 = fm ? x.map(fm) : x.slice(); | ||
var y1 = fm ? y.map(fm) : y.slice(); | ||
return hasSubsequence(x1.sort(), y1.sort(), fc, fm); | ||
} | ||
function forEach(x, fp) { | ||
@@ -898,0 +898,0 @@ x.forEach(fp); |
{ | ||
"name": "extra-array", | ||
"version": "4.0.127", | ||
"version": "4.0.128", | ||
"description": "An array is a collection of values, stored contiguously.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package