As you can run this code snippet my array.slice() seems to not work or I might have messed some other logic. After checking with different approach to extract out the array (using push) the whole code is working fine . But on this approach with slice() it doesn't extract out the copy of "width" array.
What am I missing here?
function serviceLane(cases,width) {
console.log(cases)
var b = cases.map((e,i,ar)=>{
var entry = e[0];
var exit = e[1];
console.log(entry)
console.log(exit)
console.log(width)
// var p =[];
var v=exit-entry+1;
var p = width.slice(entry,v)
console.log(p);
var m =Math.min(...p)
console.log(m)
return m ;
})
console.log(b)
return b;
}
console.log(serviceLane([ [ 0, 3 ], [ 4, 6 ], [ 6, 7 ], [ 3, 5 ], [ 0, 7 ] ],[ 2, 3, 1, 2, 3, 2, 3, 3 ]))
entry > varray will be empty andMath.min()(Math.min(...[]) in your case) with no params returnInfinity.var p = width.slice(entry,v)not working as it prompts empty array at console. You can see in the snippet also.