{"id":295,"date":"2022-01-13T16:20:32","date_gmt":"2022-01-13T09:20:32","guid":{"rendered":"http:\/\/thnkandgrow.com\/?p=295"},"modified":"2022-04-22T15:10:22","modified_gmt":"2022-04-22T08:10:22","slug":"ruby-map-and-return","status":"publish","type":"post","link":"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/","title":{"rendered":"[Ruby] Map and return?"},"content":{"rendered":"\n

H\u00f4m nay nh\u1eadn \u0111\u01b0\u1ee3c 1 c\u00e2u h\u1ecfi \u0111\u1ebfn t\u1eeb v\u1ecb tr\u00ed c\u1ee7a C\u01b0\u1eddngN\u0110, m\u00ecnh v\u1eabn ch\u01b0a t\u00ecm hi\u1ec3u l\u00fd do t\u1ea1i sao l\u1ea1i c\u00f3 k\u1ebft qu\u1ea3 kh\u00e1c nhau nh\u01b0 v\u1eady. Vi\u1ebft \u0111\u00e2y \u0111\u1ec3 nh\u1edb, mai m\u1ed1t t\u00ecm ra l\u00fd do r\u1ed3i update l\u1ea1i b\u00e0i blog n\u00e0y<\/p>\n\n\n\n

<\/p>\n\n\n\n

C\u00e2u h\u1ecfi:<\/p>\n\n\n\n

<\/p>\n\n\n\n

# ruby\narr =[[1,2], [3,4], [5,6]]\narr.map{|a,b| return a if a + b > 10}\n\n#> LocalJumpError (unexpected return)\nN\u1ebfu \u0111\u1ed5i l\u1ea1i th\u1ebf n\u00e0y\narr.map{|a,b| a if a + b > 10}\n#> [nil, nil, 5]<\/code><\/pre>\n\n\n\n

V\u00e0 n\u1ebfu \u0111\u1ec3 v\u00e0o method nh\u01b0 th\u1ebf n\u00e0y<\/p>\n\n\n\n

# ruby\n\n\ndef test_arr\n  arr =[[1,2], [3,4], [5,6]]\n  arr.map{|a, b| return a if a + b > 10}\nend\n\n#> 5<\/code><\/pre>\n\n\n\n

T\u1ea1i sao nh\u1ec9?
<\/a>
<\/p>\n","protected":false},"excerpt":{"rendered":"

H\u00f4m nay nh\u1eadn \u0111\u01b0\u1ee3c 1 c\u00e2u h\u1ecfi \u0111\u1ebfn t\u1eeb v\u1ecb tr\u00ed c\u1ee7a C\u01b0\u1eddngN\u0110, m\u00ecnh v\u1eabn ch\u01b0a t\u00ecm hi\u1ec3u l\u00fd do t\u1ea1i sao l\u1ea1i c\u00f3 k\u1ebft qu\u1ea3 kh\u00e1c nhau nh\u01b0 v\u1eady. Vi\u1ebft \u0111\u00e2y \u0111\u1ec3 nh\u1edb, mai m\u1ed1t t\u00ecm ra l\u00fd do r\u1ed3i update l\u1ea1i b\u00e0i blog n\u00e0y<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"yoast_head":"\n[Ruby] Map and return? » Th?nk And Grow<\/title>\n<meta name=\"description\" content=\"Dive deep into the latest trends and insights in technology with our engaging articles. Stay informed and ahead of the curve with our expert analysis and in-depth coverage.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Ruby] Map and return? » Th?nk And Grow\" \/>\n<meta property=\"og:description\" content=\"Dive deep into the latest trends and insights in technology with our engaging articles. Stay informed and ahead of the curve with our expert analysis and in-depth coverage.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/\" \/>\n<meta property=\"og:site_name\" content=\"Th?nk And Grow\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-13T09:20:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-22T08:10:22+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/thnkandgrow.com\/#website\",\"url\":\"https:\/\/thnkandgrow.com\/\",\"name\":\"Th?nk And Grow\",\"description\":\"Just Do It!\",\"publisher\":{\"@id\":\"https:\/\/thnkandgrow.com\/#\/schema\/person\/4056838e18c94bc665494c1e8f9f2873\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":\"https:\/\/thnkandgrow.com\/?s={search_term_string}\",\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/#webpage\",\"url\":\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/\",\"name\":\"[Ruby] Map and return? » Th?nk And Grow\",\"isPartOf\":{\"@id\":\"https:\/\/thnkandgrow.com\/#website\"},\"datePublished\":\"2022-01-13T09:20:32+00:00\",\"dateModified\":\"2022-04-22T08:10:22+00:00\",\"description\":\"Dive deep into the latest trends and insights in technology with our engaging articles. Stay informed and ahead of the curve with our expert analysis and in-depth coverage.\",\"breadcrumb\":{\"@id\":\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"item\":{\"@type\":\"WebPage\",\"@id\":\"https:\/\/thnkandgrow.com\/\",\"url\":\"https:\/\/thnkandgrow.com\/\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"position\":2,\"item\":{\"@id\":\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/#webpage\"}}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/#webpage\"},\"author\":{\"@id\":\"https:\/\/thnkandgrow.com\/#\/schema\/person\/4056838e18c94bc665494c1e8f9f2873\"},\"headline\":\"[Ruby] Map and return?\",\"datePublished\":\"2022-01-13T09:20:32+00:00\",\"dateModified\":\"2022-04-22T08:10:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/#webpage\"},\"wordCount\":89,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/thnkandgrow.com\/#\/schema\/person\/4056838e18c94bc665494c1e8f9f2873\"},\"articleSection\":[\"Technology\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/thnkandgrow.com\/blog\/2022\/01\/13\/ruby-map-and-return\/#respond\"]}]},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/thnkandgrow.com\/#\/schema\/person\/4056838e18c94bc665494c1e8f9f2873\",\"name\":\"kokorolx\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\/\/thnkandgrow.com\/#personlogo\",\"inLanguage\":\"en-US\",\"url\":\"https:\/\/s3.amazonaws.com\/thnkandgrow.com-media\/wp-content\/uploads\/2023\/05\/13223538\/Amazon-EC2.jpg\",\"contentUrl\":\"https:\/\/s3.amazonaws.com\/thnkandgrow.com-media\/wp-content\/uploads\/2023\/05\/13223538\/Amazon-EC2.jpg\",\"width\":750,\"height\":375,\"caption\":\"kokorolx\"},\"logo\":{\"@id\":\"https:\/\/thnkandgrow.com\/#personlogo\"},\"sameAs\":[\"https:\/\/thnkandgrow.com\"],\"url\":\"https:\/\/thnkandgrow.com\/blog\/author\/kokoro-lehoanggmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","_links":{"self":[{"href":"https:\/\/thnkandgrow.com\/wp-json\/wp\/v2\/posts\/295"}],"collection":[{"href":"https:\/\/thnkandgrow.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thnkandgrow.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thnkandgrow.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thnkandgrow.com\/wp-json\/wp\/v2\/comments?post=295"}],"version-history":[{"count":4,"href":"https:\/\/thnkandgrow.com\/wp-json\/wp\/v2\/posts\/295\/revisions"}],"predecessor-version":[{"id":315,"href":"https:\/\/thnkandgrow.com\/wp-json\/wp\/v2\/posts\/295\/revisions\/315"}],"wp:attachment":[{"href":"https:\/\/thnkandgrow.com\/wp-json\/wp\/v2\/media?parent=295"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thnkandgrow.com\/wp-json\/wp\/v2\/categories?post=295"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thnkandgrow.com\/wp-json\/wp\/v2\/tags?post=295"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}