Last active
June 18, 2020 22:24
-
-
Save MaxySpark/808dd36bcea0b8761c87ddefb326bef1 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
const abc = [[0,1,2],[0,1],[0],[0,1,2]]; | |
function countIndex(a, k) { | |
if (a === 0 && k === 0) { | |
return 0; | |
} else if (k !== 0) { | |
return this.countIndex(a, k-1) + 1; | |
} else { | |
const totalItem = abc[a-1].length; | |
return this.countIndex(a-1, totalItem-1) + 1 | |
} | |
} | |
for (let i=0; i<abc.length; i++) { | |
for(let j=0; j<abc[i].length; j++) { | |
console.log(countIndex(i,j)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment