December 2023
Intermediate to advanced
242 pages
5h 28m
English
| Recipe 60 | Removing Duplicate Lines Separated by Other Lines |
Suppose you want to eliminate duplicated lines that are not adjacent to each other like in the previous recipe. For instance, let’s say you have text like this:
| | Team Power Rankings |
| | #1 Cleveland Cavaliers 45-28 |
| | #2 Philadelphia 76ers 48-22 |
| | #1 Cleveland Cavaliers 45-28 |
| | #3 Memphis Grizzlies 43-27 |
| | #2 Philadelphia 76ers 48-22 |
| | #4 Boston Celtics 49-23 |
And you need to write a code that outputs:
| | Team Power Rankings |
| | #1 Cleveland Cavaliers 45-28 |
| | #2 Philadelphia 76ers 48-22 |
| | #3 Memphis Grizzlies 43-27 |
| | #4 Boston Celtics 49-23 |
Your code should have the capability to remove duplicate entries, even if they are interspersed with other lines.
Convert the string to an array, then ...
Read now
Unlock full access