Skip to content

Instantly share code, notes, and snippets.

@tol-is
Last active July 11, 2022 11:16
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tol-is/c97ac60e465811043881820e1b7945db to your computer and use it in GitHub Desktop.
Save tol-is/c97ac60e465811043881820e1b7945db to your computer and use it in GitHub Desktop.
export const carbonScale = (params = {}) => {
const {
length = 20,
minSize = 10,
intervals = 4,
increment = 2,
transform = v => v
} = params;
const getSize = count => {
if (count <= 1) {
return minSize;
}
return (
getSize(count - 1) + Math.floor((count - 2) / intervals + 1) * increment
);
};
return Array.from({ length: length }, (_, i) => getSize(i + 1)).map(
transform
);
};
const scale = carbonScale();
console.log(scale);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment