loading...

Sorted Union FCC Intermediate algorithms

95freedom95 profile image Oscar Hernandez ・1 min read

//function uniteUnique(arr, arr1, arr2, arr3) {
//var total =arr1.concat(arr2, arr3); console.log(total)
// var found = total.filter((x)=> x >= 3); console.log(found)

//var total = arr.concat(found); console.log(total);
//return total;
//}

//uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8]);
//****//

function uniteUnique(...arr) {
var arrZ = []; var arrY = []; var arrX = [];
var args =[]; var arr3 = []; var arr4 = [];
var arr5 = []; var arr6 = [];
//Slice the array array.
var arr1 = Array.prototype.slice.call(arr, 1,9);
arr1 = arr1.join(",").split(",");
arrX = arr1.filter( x => x != 3 && x != 2 && x != 1 );
//converting the array into numbers.
for(let i =0; i < arrX.length; i++){
arr3 = arrX[i]*1; arr4.push(arr3);
}
//Slice the first array.
var arr2 = Array.prototype.slice.call(arr, 0,1);
arr2 = arr2.join(",").split(",");
arrY = arr2.filter( x => x != 3 || x != 2 || x != 1 );
//converting the array into numbers.
for(let i =0; i < arrY.length; i++){
arr5 = arrY[i]*1; arr6.push(arr5);
}
args = arr6.concat(arr4); console.log(args);
return args;

}
//uniteUnique([1, 3, 2], [5, 2, 1, 4], [2, 1]);
//uniteUnique([1, 2, 3], [5, 2, 1]);
uniteUnique([1, 2, 3], [5, 2, 1, 4], [2, 1], [6, 7, 8])

//https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/sorted-union

Posted on by:

95freedom95 profile

Oscar Hernandez

@95freedom95

I AM oriented to learn new things, student at Free code camp.

Discussion

markdown guide