Created
April 25, 2017 20:12
-
-
Save Jakobud/ec056b52f3673cc369dc97f2c2428424 to your computer and use it in GitHub Desktop.
Removed an item for a SASS list based on it's index (mimics behavior of the native map-remove function)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// list-remove | |
/// Remove an item from a list | |
/// @param $list - A SASS list | |
/// @param $index - The list index to remove | |
/// @returns A SASS list | |
/// @author Jake Wilson <[email protected]> | |
@function list-remove($list, $index) { | |
$newList: (); | |
@for $i from 1 through length($list) { | |
@if $i != $index { | |
$newList: append($newList, nth($list,$i), 'space'); | |
} | |
} | |
@return $newList; | |
} |
Thank you both for this. Surprised this function doesn't exist natively yet.
I don't want to be nitpicky, but... Sass not SASS
/// @param $list - A SASS list
/// @returns A SASS list
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for sharing :)
Here is a version that allows you to use a negative n value to remove from the back of the list
and also takes into account the list separator and if the list is bracketed