Skip to content

Commit

Permalink
feat(map.depth()): add function to determine map depth.
Browse files Browse the repository at this point in the history
  • Loading branch information
sciborrudnicki committed Oct 28, 2023
1 parent f4e447d commit 41276b1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions map/_map.depth.function.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Status: DONE
// The `map.depth()` function determines the map depth.
// @param `$map` Map to check depth.
// @returns The returned value is map depth of `number`.
@function depth($map) {
$max-depth: 0;
@each $key, $value in $map {
$current-depth: 1;
@if type-of($value) == map {
$current-depth: 1 + depth($value);
}
@if $current-depth > $max-depth {
$max-depth: $current-depth;
}
}
@return $max-depth;
}

// Examples.
// $-map: (
// key-3: (
// key-2-4: 42,
// key3: (
// key-4: 100,
// key5: 200
// ),
// key6: (
// key7: (
// key8: 300
// ),
// key9: (
// key10: (
// key11: 400
// )
// ),
// )
// ),
// );

// @debug depth($-map);

0 comments on commit 41276b1

Please sign in to comment.