uniq filter

This commit is contained in:
Florian Weingarten
2014-07-29 13:09:34 +00:00
committed by Florian Weingarten
parent a8e63ff03d
commit 33e7b8e373
3 changed files with 19 additions and 0 deletions
+11
View File
@@ -108,6 +108,17 @@ module Liquid
end
end
# Remove duplicate elements from an array
# provide optional property with which to determine uniqueness
def uniq(input, property = nil)
ary = InputIterator.new(input)
if property.nil?
input.uniq
elsif input.first.respond_to?('[]'.freeze)
input.uniq{ |a| a[property] }
end
end
# Reverse the elements of an array
def reverse(input)
ary = InputIterator.new(input)