Skip to content

Instantly share code, notes, and snippets.

@MaxySpark
Last active June 18, 2020 22:24
Show Gist options
  • Save MaxySpark/808dd36bcea0b8761c87ddefb326bef1 to your computer and use it in GitHub Desktop.
Save MaxySpark/808dd36bcea0b8761c87ddefb326bef1 to your computer and use it in GitHub Desktop.
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