array sort pure javascript

Keshav Gautam
Sep 16, 2021

--

let p= [‘a’,’a’, ‘g’, ‘f’, ‘b’,’z’,’y’,’c’,’t’ ,’s’,’x’,’x’,’n’];

var output =[],match=false;

for(var a =0;a < p.length;a++ ){
match=false;

for(var b=0; b<output.length ;b++){

if(output[b]===p[a]){
match=true;
}
}

if(!match){
output.push(p[a])
}

}

console.log(output)
console.log(“a”<”b”)

function getSort (x){

for(var b=1; b<x.length ;b++){
if(x[b-1]<x[b]){

}else{
let k = x[b];
x[b]=x[b-1]
x[b-1]=k
x= getSort (x)

}

}
return x
}
console.log(getSort(output))

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Keshav Gautam
Keshav Gautam

No responses yet

Write a response