Skip to content

Instantly share code, notes, and snippets.

Created December 6, 2015 23:55
Show Gist options
  • Save anonymous/9231a94abfd505d5fdff to your computer and use it in GitHub Desktop.
Save anonymous/9231a94abfd505d5fdff to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dannycoder 's solution for Bonfire: Sorted Union
// Bonfire: Sorted Union
// Author: @dannycoder
// Challenge: http://www.freecodecamp.com/challenges/bonfire-sorted-union#
// Learn to Code at Free Code Camp (www.freecodecamp.com)
function unite(arr1, arr2, arr3) {
var newArray = [];
for(var i = 0; i < arguments.length; i++) {
for (var j = 0; j < arguments[i].length; j++)
{
//add first element to array
if( i === 0 && j === 0) {
newArray.push(arguments[i][j]);
continue;
}
//add next element if not found in the @newArray
if(newArray.indexOf(arguments[i][j]) === -1){
newArray.push(arguments[i][j]);
console.log(arguments[i][j]);
}
}
}
return newArray;
}
unite([1, 3, 2], [5, 2, 1, 4], [2, 1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment