Because it’s got a bug. See this line in del()
:
num=num.replace(num[num.length-1],'');
What does it do? It takes the last character of num, and replaces, that’s the bug, the first occurrence of that character.
Fixed version:
num = num.substr(0, num.length - 1);
0
solved JavaScript sometimes behave differently