Is it a bug? Why deleting an argument in an array gets null?

https://codecombat.com/play/level/reindeer-tender?

On this level, I cleared out all the other code lines and did this below. Please take a look the lines and my #s.

friends = hero.findFriends()

hero.say(friends[3])
#says 'comet'
hero.say(friends[4])
#says 'vixen'
hero.say(len(friends))
#says 5

del friends[3]

hero.say(len(friends))
#should says 4... but still 5

hero.say(friends[3])
#should says 'vixen'... but no.
#Line 15: ArgumentError: say's argument message should have type string, but got null. Say what?

So basically it’s like [1, 2, 3] - [2] got [1, null, 3], which should have been [1, 3] I guess.

When you delete arguments from an array, shouldn’t the array’s length get short by the number of argument you just deleted, instead of putting NULL to keep the length?

No, it’s not a bug, it’s CodeCombat Python, not pure python. CoCo python is JavaScript in dis guise:-). You can use many javascript features as filter, map, LoDash etc…, but I think the inverse will generally not work, as some exepected python code will act as javascript code.


1 Like

Thank you very much :smiley:

OMG! This works in CoCo:

x = ['a', 'b','c']
print(x)
x.remove('a')
print(x)
index = x.index('c')
del x[index]
print(x)

browser console output:

['a', 'b', 'c']
['b', 'c']
['b',]  # in python console it will be ['b']