In codekata array pblm 2. igot second test case correct but first test case wrong
Input:
3 3
23 15 16
357 65 10
Expected Output:
15 16 23 357 65 10
Actual Output:
15 16 23 65 357 10
I want 357 65 10 but I get 65 357 10 ...values greater than 100 appears in second place..i have no idea what to do and here is my program..
const readline = require("readline");
const inp = readline.createInterface({
input: process.stdin
});
const userInput = [];
inp.on("line", (data) => {
userInput.push(data);
});
inp.on("close", () => {
var a=userInput[0].split(' ');
var x=userInput[1].split(' ');
var y=userInput[2].split(' ');
var v=parseInt(a[0]);
var u=parseInt(a[1]);
for(var i=0;i<v;i++)
{
for(var j=i+1;j<v;j++)
{
if(x[i]>=x[j])
{
var t;
t=x[i];
x[i]=x[j];
x[j]=t;
}
}
}
for(var i=0;i<u;i++)
{
for(var j=i+1;j<u;j++)
{
if(y[i]<=y[j])
{
var t;
t=y[i];
y[i]=y[j];
y[j]=t;
}
}
}
var q=(x+" "+y).replace(/,/g," ");
console.log(q);
});