Skip to content
← Back to Community
I have codes in JavaScript. How can i convert it into Python
Profile icon
ManeeshSriram

//#1 -- For loop in Javascript.
const fish = ['dory', 'bruce', 'marlin', 'nemo'];
const nemo = ['nemo'];
const everyone = ['dory', 'bruce', 'marlin', 'nemo', 'gill', 'bloat', 'nigel', 'squirt', 'darla', 'hank'];
const large = new Array(10).fill('nemo');

function findNemo2(fish) {
let t0 = performance.now();
for (let i = 0; i < fish.length; i++) {
if (fish[i] === 'nemo') {
console.log('Found NEMO!');
}
}
let t1 = performance.now();
console.log("Call to find Nemo took " + (t1 - t0) + " milliseconds.");
}

findNemo2(everyone)

Voters
Profile icon
awsalam
Profile icon
DevAdedoyin
Profile icon
MurtazaKanorwa1
Profile icon
ramyani-ghosh
Profile icon
AnastassiyaM
Profile icon
AmirGolpayegani
Profile icon
ManeeshSriram
Comments
hotnewtop
Profile icon
Geocube101

If for some reason you need this converted from JS to Python, I can do that for you

Converted Repl
Let me know if it doesn't work as intended

Profile icon
SixBeeps

You cannot simply "translate" from one language to another without knowing both of the languages. If you don't know how to translate from one to another, then you don't know one of the languages.