Last active
November 7, 2022 09:06
-
-
Save DavidBernalGonzalez/1e119272f222c45dce122a8cd5d7521e to your computer and use it in GitHub Desktop.
This file contains 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
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