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

array-lib

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-lib - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

124

Array.js

@@ -1,35 +0,1 @@

/**
* @Array.matrix
* @Array.vector
* @String.prototype.toArray
* @Array.prototype.clone
* @Object.prototype.clone
* @Array.prototype.pos
* @Array.prototype.print
* @String.prototype.print
* @Boolean.prototype.print
* @Number.prototype.print
* @Object.prototype.print
* @Array.prototype.add
* @Array.prototype.add_up
* @Array.prototype.max
* @Array.prototype.max_index
* @Array.prototype.min
* @Array.prototype.min_index
* @Array.prototype.sort_by
* @Array.prototype.remove
* @Array.prototype.remove_val
* @Array.prototype.count
* @Array.prototype.replace
* @Array.prototype.avrage
* @Array.prototype.multiplyMatrices
* @Array.prototype.isMatrix
* @Array.prototype.getAllPos
* @function multiplyMatrices
*
* future:
*
*
*/
if (!Array.matrix) {

@@ -45,2 +11,23 @@ Array.matrix = function (x, y, fill) {

}
if(!Array.range){
Array.range = function(start = 0,stop,step = 1){
let arr = []
if(start == 0 && (!stop || stop === 0 )|| start == stop){
return arr;
}else if(!stop){
for (let i = 0; i < start; i++) {
arr.push(i);
}
}else if(start > stop && step < 0){
for(let i = start;i > stop;i+= step ){
arr.push(i);
}
}else if(start < stop && step > 0){
for(let i = start;i < stop;i+= step ){
arr.push(i);
}
}
return arr;
}
};

@@ -61,3 +48,2 @@ if (!String.prototype.toArray) {

}
//return deep copy of array.
if (!Array.prototype.clone) {

@@ -72,8 +58,8 @@ Array.prototype.clone = function () {

try {
return JSON.parse(JSON.stringify(this.valueOf()));
}catch {
return JSON.parse(JSON.stringify(this.valueOf()));
} catch {
let target = {};
for (let prop in this) {
if (this.hasOwnProperty(prop)) {
target[prop] = src[prop];
target[prop] = src[prop];
}

@@ -86,3 +72,2 @@ }

//return position of element ,if not found returns false.
if (!Array.prototype.pos) {

@@ -99,3 +84,3 @@ Array.prototype.pos = function (e) {

}
//prints array to console
if (!Array.prototype.print) {

@@ -144,3 +129,3 @@ Array.prototype.print = function () {

if (!Array.prototype.add_up) {
if (!Array.prototype.addUp) {
Array.prototype.add_up = function () {

@@ -163,3 +148,3 @@ let arr = this.filter(x => typeof x === "number");

}
if (!Array.prototype.max_index) {
if (!Array.prototype.maxIndex) {
Array.prototype.max_index = function () {

@@ -182,3 +167,3 @@ let arr = this.filter(x => typeof x === "number");

}
if (!Array.prototype.min_index) {
if (!Array.prototype.minIndex) {
Array.prototype.min_index = function () {

@@ -192,3 +177,3 @@ let arr = this.filter(x => typeof x === "number");

}
if (!Array.prototype.sort_by) {
if (!Array.prototype.sortBy) {
Array.prototype.sort_by = function (type) {

@@ -212,3 +197,3 @@ if (type === "length") {

if (!Array.prototype.remove_val) {
if (!Array.prototype.removeVal) {
Array.prototype.remove_val = function (val, all = false) {

@@ -309,15 +294,44 @@ if (all) {

Array.prototype.getAllPos = function(val){
let positions = [];
this.valueOf().forEach((e,i) => {
if(e === val){
positions.push(i);
}
})
return positions;
if (!Array.prototype.getAllPos) {
Array.prototype.getAllPos = function (val) {
let positions = [];
this.valueOf().forEach((e, i) => {
if (e === val) {
positions.push(i);
}
})
return positions;
}
}
if(!Array.prototype.shuffle){
Array.prototype.shuffle = function() {
var i = this.length, j, temp;
if ( i == 0 ) return this;
while ( --i ) {
j = Math.floor( Math.random() * ( i + 1 ) );
temp = this[i];
this[i] = this[j];
this[j] = temp;
}
return this;
};
};
if(!Array.prototype.without){
Array.prototype.without = function(val){
let args = [];
let arr = [];
for (let i = 0; i < arguments.length; i++) {
args.push(arguments[i]);
}
this.forEach(e => {
if(args.indexOf(e) === -1){
arr.push(e);
}
})
return arr;
}
};
module.exports = {
multiplyMatrices,
}
}
{
"name": "array-lib",
"version": "0.0.8",
"version": "0.0.9",
"description": "A library for array functions in Array.prototype",

@@ -20,3 +20,6 @@ "main": "Array.js",

"Multiply matrices",
"sort"
"sort",
"shuffle",
"range",
"without"
],

@@ -23,0 +26,0 @@ "author": "dovid crow",

@@ -22,3 +22,3 @@ # array-lib

**Print an array:**<br>
also supports boolian number and string
also supports: boolean, number ,and string.
****

@@ -39,3 +39,3 @@ ```js

```js
arr.max_index().print()
arr.maxIndex().print()
```

@@ -55,3 +55,3 @@ **Removes element at the specified position:**

let remove_all_elements = true;
a.remove_val(4,remove_all_elements);
a.removeVal(4,remove_all_elements);

@@ -80,3 +80,3 @@ a.print();//=> [1,2,3,5,5];

d.add_up().print();//=> 15
d.addUp().print();//=> 15
```

@@ -149,2 +149,31 @@ **Create 2d array:**

```
**shuffle an array**
****
```js
[1,2,3,4,5,6,7,8,9].shuffle().print();
//=> [ 7, 2, 9, 1, 6, 8, 3, 5, 4 ]
```
**range**<br>
A function to create flexibly-numbered lists of integers
****
```js
Array.range(10);
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Array.range(1, 11);
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Array.range(0, 30, 5);
//=> [0, 5, 10, 15, 20, 25]
Array.range(0, -10, -1);
//=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
Array.range(0);
//=> []
```
**without**<br>
Returns a copy of the array with all instances of the values removed.
```js
let a = [1,2,3,1,2,31,2,31,1,2,3,]
let b = a.without(1,2);
b.print();
//=>[ 3, 31, 31, 3 ]
```
## Chaining

@@ -151,0 +180,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