This file contains hidden or 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
a = ["a", "b", "c"] | |
a.cycle(2) {|x| puts x } # a, b, c, a, b, c. |
This file contains hidden or 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
var collect [4]int | |
integers := [4]int{1, 2, 3, 4} | |
for i := 0; i < len(integers); i++ { | |
collect[i] = integers[i] * integers[i] | |
if i == len(integers) - 1 { | |
fmt.Println(collect) | |
} | |
} |
This file contains hidden or 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
(1..4).collect {|i| i*i } #=> [1, 4, 9, 16] | |
(1..4).collect { "cat" } #=> ["cat", "cat", "cat", "cat"] |
This file contains hidden or 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
length := 4 | |
var any [length]bool | |
fruits := [length]string{"Apple", "Mango", "Orange", "Banana"} | |
for i := 0; i < len(fruits); i++ { | |
any[i] = len(fruits[i]) > length | |
} | |
for v := range any { |
This file contains hidden or 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
fruits = ["Apple", "Mango", "Orange", "Banana"] | |
fruits.any? { |word| word.length < 4 } # false | |
fruits.any? { |word| word.length > 5 } # true |
This file contains hidden or 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
package main | |
import "fmt" | |
func is_lengthy(length int, fruits []string) bool { | |
var all = make([]bool,len(fruits)) | |
var cond bool | |
for i := 0; i < len(fruits); i++ { | |
all[i] = len(fruits[i]) > length | |
} |
This file contains hidden or 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
var cond bool | |
for v := range basket { | |
if cond = basket[v] == true; cond == false { | |
break | |
} | |
} | |
return cond |
This file contains hidden or 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
var basket = make([]bool,len(fruits)) | |
for i := 0; i < len(fruits); i++ { | |
basket[i] = len(fruits[i]) > length | |
} |
This file contains hidden or 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
["Apple", "Orange"].all? { |fruit| fruit.length > 5 } | |
=> false |
This file contains hidden or 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
["Apple", "Orange"].all? { |fruit| fruit.length > 4 } | |
=> true |