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

array-rearrange

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-rearrange - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

28

index.js

@@ -7,17 +7,26 @@ 'use strict'

function reorder(arr, index, stride) {
var n = index.length;
var n = index.length
if (!stride) stride = 1;
if (!stride) {
stride = Math.floor(arr.length / index.length);
}
if (stride === 1) {
for (var i=0; i<n; i++) {
reorderSimple()
}
else {
reorderStride(stride)
}
function reorderSimple () {
for (var i=0; i < n; i++) {
while (index[i] != i) {
var id = index[i]
var oldId = index[id];
index[id] = id;
index[i] = oldId;
var value = arr[id];
arr[id] = arr[i];
index[id] = id;
index[i] = oldId;
arr[i] = value;

@@ -27,4 +36,5 @@ }

}
else {
for (var i=0; i<n; i+=stride) {
function reorderStride (stride) {
for (var i=0; i < n; i+=stride) {
while (index[i] != i) {

@@ -31,0 +41,0 @@ var id = index[i]

{
"name": "array-rearrange",
"version": "2.0.0",
"version": "2.1.0",
"description": "Rearrange array elements by index array",

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

@@ -17,1 +17,12 @@ 'use strict'

assert.deepEqual(reorder([4,4, 3,3, 2,2, 1,1], [3,2,1,0], 2), [1,1, 2,2, 3,3, 4,4])
assert.deepEqual(reorder([4,4, 3,3, 2,2, 1,1], [3,2,1,0]), [1,1, 2,2, 3,3, 4,4])
// perf
let N = 1e6
let a = Array.from({length: N}, Math.random)
let idx = Array.from({length: N}, (v, i) => (N - i - 1))
console.time(1)
reorder(a, idx)
console.timeEnd(1)
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