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

extra-array

Package Overview
Dependencies
Maintainers
1
Versions
856
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

extra-array - npm Package Compare versions

Comparing version 2.0.13 to 2.0.14

62

fresh.js

@@ -23,2 +23,11 @@ // PURE FUNCTIONS

/**
* Gets elements before last element.
* @param {Array} x array
* @returns {Array} elements before last
*/
function init(x) {
return x.slice(0, -1);
}
/**
* Gets elements after head.

@@ -33,11 +42,26 @@ * @param {Array} x array

/**
* Gets elements before last element.
* Gets all initial segments.
* @param {Array} x array
* @returns {Array} elements before last
* @returns {Array} [initial segment ...]
*/
function init(x) {
return x.slice(0, -1);
function inits(x) {
var a = [];
for(var i=0, I=x.length; i<I; i++)
a.push(x.slice(0, i));
return a;
}
/**
* Gets all final segments.
* @param {Array} x array
* @returns {Array} [final segment ...]
*/
function tails(x) {
var a = [];
for(var i=0, I=x.length; i<I; i++)
a.push(x.slice(i));
return a;
}
/**
* Gets largest element, as per compare function.

@@ -98,11 +122,24 @@ * @param {Array} x array

function takeWhile(x, fn, ths=null) {
var a = [], i = -1;
for(var e of x) {
if(fn.call(ths, e, ++i, x)) a.push(e);
else break;
}
return a;
return x.slice(0, findFailIndex(x, fn, ths));
}
/**
* Get suffix remaining after takeWhile().
* @param {Array} x array
* @param {function} fn filter function (elem, index, array)
* @param {object?} ths this argument
* @returns {Array} suffix
*/
function dropWhile(x, fn, ths=null) {
return x.slice(findFailIndex(x, fn, ths));
}
function findFailIndex(x, fn, ths=null) {
var i = -1;
for(var e of x)
if(!fn.call(ths, e, ++i, x)) break;
return i;
}
/**
* Splits array to elements which do, and dont satify the filter.

@@ -165,4 +202,6 @@ * @param {Array} x array

exports.last = last;
exports.init = init;
exports.tail = tail;
exports.init = init;
exports.inits = inits;
exports.tails = tails;
exports.max = max;

@@ -173,4 +212,5 @@ exports.min = min;

exports.takeWhile = takeWhile;
exports.dropWhile = dropWhile;
exports.partition = partition;
exports.zip = zip;
exports.append = append;

2

package.json
{
"name": "extra-array",
"version": "2.0.13",
"version": "2.0.14",
"description": "Standard utility methods for Array.",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,2 +5,3 @@ cons

intercalate
dropWhileEnd

@@ -7,0 +8,0 @@ remove

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