Advertisement
v3ry

Untitled

May 24th, 2022
758
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function orderWeight(strng) {
  2.     strng = strng.split(" ")
  3.   const lgtStrng= strng.length
  4.   const myDic = []
  5.   const myDic2 = []
  6.   let temp = 0
  7.   for (i in strng){
  8.     for(j in strng[i]){
  9.       temp+= parseInt(strng[i][j])
  10.     }
  11.     console.log(temp)
  12.     myDic.push(temp)
  13.     temp = 0
  14. //     element.split("").reduce((a,b)=> a+b)
  15.   }
  16.   let bool= false;
  17.   let ind=0;
  18.   let indede=0
  19.   let minVal=9999;
  20.   while(bool ==false){
  21.     minVal=9999
  22.     ind=0
  23.     for(k in myDic){
  24.       if(myDic[k]<minVal){
  25.         minVal=myDic[k]
  26.         ind=k
  27.       }
  28.     }
  29.     myDic2.push(strng[ind])
  30.     strng.splice(ind,1)
  31.     myDic.splice(ind,1)
  32.     console.log(myDic)
  33.     indede++
  34.     if(indede >= lgtStrng){
  35.       bool = true
  36.     }
  37.   }
  38.   console.log(myDic)
  39.   console.log(myDic2.join(" "))
  40.   console.log(strng)
  41.   return myDic2.join(" ")
  42. }
  43.  
Advertisement
RAW Paste Data Copied
Advertisement