Skip to content

Instantly share code, notes, and snippets.

@theremon
Created January 30, 2023 11:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theremon/587b324f961f97f1aa37963c77628507 to your computer and use it in GitHub Desktop.
Save theremon/587b324f961f97f1aa37963c77628507 to your computer and use it in GitHub Desktop.
Given a positive integer, generate an array in which every element is an array that goes from 1 to the index of that array
const generateArrays = (len) => {
return Array(len)
.fill()
.map((item, idx) => {
return [...Array(idx + 1).keys()].map((x) => x + 1);
});
};
console.log(generateArrays(5));
console.log(generateArrays(1));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment