Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
How to replace the empty values "" on same index from another array

I have to string arrays as follows both arrays size (count) same but values of both arrays are not the same.

arrayAlpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"] 
          
arrayNume  = ["", "", "3", "4", "", "6", "", "", "9", ""] 

mixArray = [String]()

I want another Array called MixUPCArray which will have the values of both arrays as the same as the current index. First, it will load the UPC values for the positions of an empty string "" in the chosenProductUPCArray then keep the chosenProductUPCArray arrays string values on the as position as it is.

so the output will be like this

MixArray   = ["a", "b", "3", "4", "e", "6", "g", "h", "9", "j"]

Keep in mind that ArrayAlpha and ArrayNume size is always the same and just some empty values are coming in ArrayNume but ArrayAlpha always contains the full values

Please write the best solution for this in swift MixArray also same size as the both arrays.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can zimply zip both arrays and map the resulting tuples. If the second element is empty return the first otherwise return the second:

let arrayAlpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
let arrayNume  = ["", "", "3", "4", "", "6", "", "", "9", ""]

let mixArray = zip(arrayAlpha, arrayNume).map { $1.isEmpty ? $0 : $1 }

print(mixArray)  // ["a", "b", "3", "4", "e", "6", "g", "h", "9", "j"]
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda