Skip to content

Instantly share code, notes, and snippets.

@dmitry-ilyashevich
Created January 24, 2014 13:28
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 dmitry-ilyashevich/8597235 to your computer and use it in GitHub Desktop.
Save dmitry-ilyashevich/8597235 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// Sass (v3.3.0.rc.2)
// Compass (v1.0.0.alpha.17)
// ----
// Counts the number of occurrences of each value of $list
// -------------------------------------------------------------------------------
// @param $list [List] : list
// -------------------------------------------------------------------------------
// @return [Map]
@function count-values($list) {
$map: ();
@each $item in $list {
$index: map-get($map, $item);
$value: if($index, $index + 1, 1);
$map: map-merge($map, ($item: $value));
}
@return $map;
}
$list: test string banana abc string a banana test;
$count: count-values($list);
sass {
count-values: inspect($count);
}
sass {
count-values: (test: 2, string: 2, banana: 2, abc: 1, a: 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment