Skip to content

Instantly share code, notes, and snippets.

@DavidBernalGonzalez
Last active November 7, 2022 09:06
Show Gist options
  • Save DavidBernalGonzalez/1e119272f222c45dce122a8cd5d7521e to your computer and use it in GitHub Desktop.
Save DavidBernalGonzalez/1e119272f222c45dce122a8cd5d7521e to your computer and use it in GitHub Desktop.
const arr5 = ["🌶", "🥛", "🌶", "🥛", "🌶", "🥛"];
const result = [];
arr5.map((item, index, array) => {
/*
if (item === "🌶" && array[index + 1] === "🥛") {
//console.log("La 🌶 está aquí: " + index);
//console.log("La 🥛 está aquí: " + (index + 1));
//array.splice(index + 1, 1, "🥵");
result.push(item);
result.push("🥵");
//document.write(result);
//document.write("<br>")
} else {
result.push(item);
}*/
return item === "🌶" && array[index + 1] === "🥛"
? result.push(item, "🥵")
: result.push(item);
});
console.log(result);
//Con bucle FOR + splice
for (let i=0; i<arr5.length; i++) {
if (arr5[i] == "🌶") {
arr5.splice(i+1, 0, '🥵');
}
}
console.log(arr5);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment