I came up with a solution to a problem I was facing, but I'm not entirely comfortable with it. It feels risky to me, like using an array to redefine itself is not a good coding practice. It's similar to trying to explain a word by using the word itself in the definition. Can someone please help me understand why this approach might be incorrect, or if it's actually acceptable?
let array = []
// other actions are performed to populate the array
array = array.filter(element => element !== true)
I chose to go this route because I need to keep the variable name (array
) consistent throughout the function. The array's contents could be modified multiple times before it's finally returned, depending on other actions taking place within the function.
If this explanation is unclear, please let me know so I can provide more details. Thank you!