Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
839 B
5
Indexable
Never
let a=[1,2,90,'d','e',2,'r',4,4,'t'];
console.log("after sorting= ", a)
let low=0;
let high=a.length-1;
while(low<=high){
  if(typeof a[low]=="string"){
    let temp=a[low];
    a[low]=a[high];
    a[high]=temp;
    high--;
  }else
  low++;
}
console.log("after sortign first stage complete= ", a);

console.log("sorting only number ")
for(let i=0;i<a.length;i++){
  if(typeof a[i]!="string"){
  for(let j=i+1;j<a.length;j++){
    if(a[j]<a[i]){
      let temp=a[j];
      a[j]=a[i];
      a[i]=temp;
    }
  }
  }else{
    break;
  }
}
console.log("only number is sorting", a)


console.log("sorting only string ")
for(let i=0;i<a.length;i++){
  if(typeof a[i]!="number"){
  for(let j=i+1;j<a.length;j++){
    if(a[j]<a[i]){
      let temp=a[j];
      a[j]=a[i];
      a[i]=temp;
    }
  }
  }
}
console.log("only string is sorting", a)