There is some code which is GPL or LGPL that I am considering using for an iPhone project.

If I took that code (JavaScript) and rewrote it in a different language for use on the iPhone would that be a legal issue?

In theory the process that has happened is that I have gone through each line of the project, learnt what it is doing, and then reimplemented the ideas in a new language.

To me it seems this is like learning how to implement something, but then reimplementing it separately from the original licence. Therefore you have only copied the algorithm, which arguably you could have learnt from somewhere else other than the original project.

Does the licence cover the specific implementation or the algorithm as well?

EDIT------

Really glad to see this topic create a good conversation. To give a bit more backing to the project, the code involved does some kind of audio analysis. I believe it is non-trivial to learn or implement, although I was prepared to embark on this task (I'm at the level where I can implement an FFT algorithm, and this was going to go beyond that.) It is a fairly low LOC script, so I didn't think it would be too hard to do a straight port.

I really like the idea of rereleasing my port as well as using it in the application. I don't see any problem with that, and it would be a great way to give something back to the community.

I was going to add a line about not wanting to discuss the moral issues, but I'm quite glad I didn't as it seems to have fired the debate a bit. 

I still feel a bit odd about using open source code to learn from. Does this mean that anything one learns from an open source project is not allowed to be used in a closed source project? And how long after or different does an implementation have to be to not be considered violation of the licence? Murky!

EDIT 2 --------

Follow up question

I am not a lawyer. This is not legal advice.

That said, taking every line of an application and changing it slightly for the sole purpose of circumventing copyright law is blatantly, obviously, creating a derived work with no plausible defense whatsoever. Even the boughtest judge and jury will definitely find against you if you ever get dragged into court. 

Just as a comparison: companies who do need to rewrite something for interoperability usually hire different sets of people to understand the source, and to create the port ("clean-room implementation"), so that no one can accuse them of creating a derived work. What you propose is the exact opposite.
