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

203
Visualizações
How to write a javascript program that returns the subset of a string as an array?

I have seen examples but I still dont understand all of it. I know substring() is definately used but I need a step by step breakdown if possible. Thank you very much :)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First you can split the string using String.split() method and then you can create combinations with the elements by pushing in new array.

Working Demo :

// Input string
let str = "dog";
// An empty array which will store the combinations.
let result = [];

/**
 * getCombination() method is used to get all the combinations of all the array elements passed as a parameter.
 */
function getCombination(inputArr) {
  // variable which will store the combination string.
  let temp = '';
  // Iterating input array to get elements one by one.
  inputArr.forEach((elem, index) => {
    // Pushing the element into result array.
    result.push(temp + elem);
    // To make the combination updating temp variable with the elem. 
    temp += elem + "";
  });
}
 
// Once combination done for one iteration, removing the first element from an array and then again calling getCombination() method to get the combination for next set of elements.
str.split('').forEach((elem, index) => {
    getCombination([...str.slice(index)]);
});

// Expected result
console.log(result);

about 4 years ago · Juan Pablo Isaza 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