-
-
Save rubenribeiro/7b02b9b0e24bcb0e88a1 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/dannycoder 's solution for Bonfire: Sorted Union
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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