Skip to content

[New Feature]: Suggestions #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 33 additions & 36 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,47 +1,44 @@
/*!
* arr-diff <https://github.com/jonschlinkert/arr-diff>
*
* Copyright (c) 2014-2017, Jon Schlinkert.
* Released under the MIT License.
*/

'use strict';

module.exports = function diff(arr/*, arrays*/) {
var len = arguments.length;
var idx = 0;
while (++idx < len) {
arr = diffArray(arr, arguments[idx]);
}
return arr;
};

function diffArray(one, two) {
if (!Array.isArray(two)) {
return one.slice();
function performArrayDiff(arrayOne, arrayTwo) {
/* yes we need to make sure that the second argument in this is always an array */
if (!Array.isArray(arrayTwo)) {
return arrayOne.slice(0);
}
else {
/* take a clone so that you do not affect the original values */
let sourceArray = arrayOne.slice(0);
let diffArray = arrayTwo.slice(0);

var tlen = two.length
var olen = one.length;
var idx = -1;
var arr = [];
let resultArray = [];

while (++idx < olen) {
var ele = one[idx];
sourceArray.forEach((value) => {
let foundIndex = diffArray.findIndex((element) => {
return element === value;
});

var hasEle = false;
for (var i = 0; i < tlen; i++) {
var val = two[i];

if (ele === val) {
hasEle = true;
break;
if (foundIndex === -1) {
resultArray.push(value);
}
}
});

if (hasEle === false) {
arr.push(ele);
return resultArray;
}
}

module.exports = (array) {
if (!Array.isArray(array)) {
throw new Error("First Argument: 'array' needs to always be an array!");
}
else {
let argsLength = arguments.length;
let index = 1;

/* iteration */
while (index < argsLength) {
array = performArrayDiff(array, arguments[index]);
++index;
}
return array;
}
return arr;
}