Created
June 15, 2017 16:41
-
-
Save JacksonRMC/9f433e18c7b4b106938efacb77c570af to your computer and use it in GitHub Desktop.
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
var maxEnvelopes = function(envelopes) { | |
let dollArray = []; | |
envelopes.forEach((element) => { | |
if(typeof element === 'number') { | |
dollArray.push(element); | |
} else { | |
element.forEach(x => { | |
dollArray.push(x); | |
}) | |
} | |
}) | |
let finalEnv = []; | |
let newEnv = new Set(dollArray); | |
let array = [...newEnv].sort((a, b) => { | |
return a - b; | |
}) | |
for ( let i = 0 ; array.length % 2 === 0 ? i < array.length : array.length - 1 ; i += 2) { | |
finalEnv.push([array[i], array[i + 1]]); | |
} | |
return finalEnv; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment