ganrath07
BAN USER
Comments (3)
Reputation 0
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
and
}
//let arr = [-1,1,3,-2,2];
let arr = [1,0,3,5,0,7,9,6,0,1]
let resulr = [...arr];
let neg = []
arr.find((item) =>{
if(item === 0){
neg.push(item);
}
})
let test = resulr.join('')
test = test.replace(/0/gi,'')
test = test.split('').map( Number );
test.push(...neg)
console.log(test)
and
}
- ganrath07 January 13, 2020Comment hidden because of low score. Click to expand.
0
of 0 vote
I hope it will work :
//let arr = [-1,1,3,-2,2];
let arr = [-5,1,3,7,-4,-2,9,2]
let resulr = [...arr];
let neg = []
arr.find((item) =>{
if(item <0){
neg.push(item);
}
})
resulr.unshift(...neg)
console.log(resulr)
let final = [...new Set([...resulr])];
console.log(final)
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
javascript solution :
let arr = [2,4,7,8,9,10,23,45,6,12];
function swap(swapval){
let index = arr.indexOf(swapval);
let cal = arr.length - index ;
let val = arr[cal - 1];
console.log(val);
let result = arr.join(',');
var reg = new RegExp(val,"i")
result = result.replace(reg,swapval);
var reg = new RegExp(swapval,"i")
result = result.replace(reg,val);
result = result.split(',').map(Number)
return result;
}
console.log(swap(7));
- ganrath07 January 13, 2020