Skip to content

Latest commit

 

History

History
45 lines (30 loc) · 429 Bytes

add_uniq_value_to_array.md

File metadata and controls

45 lines (30 loc) · 429 Bytes

How to add uniq value to array

array = [1, 2, 3]

bad

array << 2
array << 4

# Result:
# [1, 2, 3, 2, 4]

p array.uniq

# Result:
# [1, 2, 3, 4]

good (but need refactor)

array = array | [2]
array = array | [4]

p array

# Result:
# [1, 2, 3, 4]

good

array |= [2, 4]

p array

# Result:
# [1, 2, 3, 4]

View Source