Last active
February 9, 2022 02:48
-
-
Save natafaye/fbd6ff2acf1c3620f7ad23a428fca290 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
// The same thing as the other one, I just changed the syntax of the first two lines to ES6 Classes, if that makes it clearer | |
class List { | |
countSpecDigits(integersList, digitsList){ | |
// keep a tally of the digits that I see that I'm supposed to count | |
const tallyList = digitsList.map(number => [number, 0]); | |
// loop over the list of integers | |
for(const integer of integersList) { | |
const integerDigitList = String(integer).split("").map(Number); | |
for(const digit of integerDigitList) { | |
// make our check | |
// make sure to ignore NaN | |
if( digitsList.includes(digit) ) { | |
// go into tally list, find the right array and increment to the tally spot | |
const tallyPair = tallyList.find(pair => pair[0] === digit); | |
tallyPair[1] += 1; | |
} | |
} | |
} | |
return tallyList; | |
} | |
} |
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
function List(){ | |
this.countSpecDigits=function(integersList, digitsList){ | |
// keep a tally of the digits that I see that I'm supposed to count | |
const tallyList = digitsList.map(number => [number, 0]); | |
// loop over the list of integers | |
for(const integer of integersList) { | |
const integerDigitList = String(integer).split("").map(Number); | |
for(const digit of integerDigitList) { | |
// make our check | |
// make sure to ignore NaN | |
if( digitsList.includes(digit) ) { | |
// go into tally list, find the right array and increment to the tally spot | |
const tallyPair = tallyList.find(pair => pair[0] === digit); | |
tallyPair[1] += 1; | |
} | |
} | |
} | |
return tallyList; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment