How to convert array with ranges in to alone array in ruby -


मेरे पास कुछ सरणी है

  & gt; & gt; A = ["a..c", "0..2"] = & gt; ["A..c", "0..2"]   

मुझे इस सरणी को अन्य सरणी में बदलने की आवश्यकता है

  & gt; & gt; बी = ("a" .. "c")। To_a + (0..2) .to_a = & gt; ["A", "b", "c", 0, 1, 2]   

मैं यह कैसे कर सकता हूं?

इसके बारे में क्या?

  a = ["a .. C "," 0..2 "] b = a.map {| e | रेंज.न्यू (* (ई)। एसप्लीट ('..')) .to_a}। फ़्लैटन   

नहीं flat_map उपयोग किया जाता है, इसलिए यह सभी पर समान कार्य करता है संस्करण

के रूप में ठीक से वर्णित है, यह संस्करण पूर्णांक में परिवर्तित नहीं होता है।

यहां एक संस्करण है जो:

  b = a मानचित्र करो | ई | रेंज.न्यू (* (ई) .split ('..')। Map {| c | c = ~ / \ A \ d + \ z /? C.to_i: c}) .to_a end.flatten   

इसे कार्रवाई में देखें

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -