Array#-() es un método de clase Array que realiza una operación de diferencia de conjuntos eliminando los elementos similares de las dos arrays.
Sintaxis: Array.-()
Parámetro: Arreglos para realizar la operación de concatenación.
Retorno: Nuevas arrays eliminando los mismos elementos de las dos arrays.
Ejemplo 1 :
# Ruby code for -() method # showing concatenate operation # declaring array a = [18, 22, 33, 4, 5, 6] # declaring array b = [5, 4, 22, 1, 88, 9] # declaring array c = [18, 22, 33, 40, 50, 6] # differencing arrays puts "difference of a and b : #{a - b}\n\n" # differencing arrays puts "difference of a and c : #{a - c}\n\n" # differencing arrays puts "difference of b and c : #{b - c}\n\n"
Producción :
difference of a and b : [18, 33, 6] difference of a and c : [4, 5] difference of b and c : [5, 4, 1, 88, 9]
Ejemplo #2:
# Ruby code for -() method # showing concatenate operation # declaring array a = ["abc", "xyz", "dog"] # declaring array b = ["cow", "cat", "dog"] # declaring array c = ["cat", "1", "dog"] # differencing arrays puts "difference of a and b : #{a - b}\n\n" # differencing arrays puts "difference of a and c : #{a - c}\n\n" # differencing arrays puts "difference of b and c : #{b - c}\n\n"
Producción :
difference of a and b : ["abc", "xyz"] difference of a and c : ["abc", "xyz"] difference of b and c : ["cow"]
Publicación traducida automáticamente
Artículo escrito por mayank5326 y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA