Created
December 20, 2016 17:40
-
-
Save erottman/269537e16552286e9ac11ea14c17043f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 creditCards = ['4916-2600-1804-0530', '4779-252888-3972', '4252-278893-7978', '4556-4242-9283-2260']; | |
function largestNum(array) { | |
var max = 0; | |
var largestSum; | |
for (var i = 0; i < array.length; i++) { | |
var totalOfEachCreditCard = 0; | |
var arrayToString = array[i]; | |
console.log(arrayToString); | |
for (var j = 0; j < arrayToString.length; j++) { | |
var sumIntegers = parseInt(arrayToString.charAt(j)); | |
if(sumIntegers) { | |
totalOfEachCreditCard += sumIntegers; | |
console.log(totalOfEachCreditCard); | |
} | |
} | |
if(totalOfEachCreditCard >= max) { | |
max = totalOfEachCreditCard; | |
largestSum = array[i]; | |
} | |
} | |
console.log(max); | |
console.log(largestSum); | |
return largestSum; | |
} | |
largestNum(creditCards); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment