The Javascript code to find missing number doesn't work in IE 11 but works in Chrome and Firefox. I just learned that IE 11 doesn't support EMCA 6.0
Need to redo this line for(var i=Math.min(...arr); i<Math.max(...arr); i++){
var str = "1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21;22;23;24;25;26;27;28;29;30;31;32;33;34;35;36;37;38;39;40;41;42;43;44;45;46;47;48;49;50;51;52;53;54;55;56;57;58;59;60;61;62;63;64;65;66;67;68;69;70;71;72;75;76;77;78;79;80;81;82;83;84;85;86;87;88;89;90;91;92;1001;1002;1003;1004;1005;1006;1007;73;";
function getMissingNumber(str){
var arr = str.split(/\;/);
var missingNum = [];
for(var i=Math.min(...arr); i<Math.max(...arr); i++){
if(arr.indexOf(i.toString()) === -1){
missingNum.push(i);
if(i){
alert(i);return; }
}
}
return missingNum;
}
console.log(getMissingNumber(str));
//alert(getMissingNumber(str));
Some answers suggest you to transpile your code to ES5 (with babel) and it is a working solution.
So if your project is big and you use lot of ES6 features that are not supported in IE11 (and you want to support IE11) then babel and/or other tools are worth checking (webpack, parcelJs, etc).
But if you just need to make this code IE11/ES5 compliant you can just call Math.min
with apply
, like this ;
Math.min.apply(null, array)
Example with spread operator (...) and apply : https://repl.it/@Benoit_Vasseur/spread-operator-to-ES5-for-array
Apply documentation : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply