You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 14, 2021. It is now read-only.
// 2. Let n be an integer for which the exact mathematical value of n ÷ 10f – x is as close to zero as possible. If there are two such n, pick the larger n.
808
+
letp=Math.pow(10,f)*x;// ###TODO: add description for this variable p
809
+
letn=p>Math.floor(p) ? Math.round(p) : p+1;
810
+
// 3. If n = 0, let m be the String "0". Otherwise, let m be the String consisting of the digits of the decimal representation of n (in order, with no leading zeroes).
811
+
letm=(n===0 ? "0" : (n+'').split('.')[0]);
812
+
813
+
letint;
814
+
// 4. If f ≠ 0, then
815
+
if(f!==0){
816
+
// a. Let k be the number of characters in m.
817
+
letk=m.length;
818
+
// a. If k ≤ f, then
819
+
if(k<=f){
820
+
// i. Let z be the String consisting of f+1–k occurrences of the character "0".
821
+
letz=arrJoin.call(Array(f+1-k+1),'0');
822
+
// ii. Let m be the concatenation of Strings z and m.
823
+
m=z+m;
824
+
// iii. Let k be f+1.
825
+
k=f+1;
826
+
}
827
+
// a. Let a be the first k–f characters of m, and let b be the remaining f characters of m.
828
+
leta=m.slice(0,k-f),b=m.slice(-(k-f));
829
+
// a. Let m be the concatenation of the three Strings a, ".", and b.
830
+
m=a+"."+b;
831
+
// a. Let int be the number of characters in a.
832
+
int=a.length;
827
833
}
828
-
834
+
// 5. Else, let int be the number of characters in m.
835
+
elseint=m.length;
836
+
// 6. Let cut be maxFraction – minFraction.
837
+
letcut=maxFraction-minFraction;
829
838
// 7. Repeat while cut > 0 and the last character of m is "0":
830
839
while(cut>0&&m.slice(-1)==="0"){
831
840
// a. Remove the last character from m.
832
841
m=m.slice(0,-1);
833
-
834
-
// b. Decrease cut by 1.
842
+
// a. Decrease cut by 1.
835
843
cut--;
836
844
}
837
-
838
845
// 8. If the last character of m is ".", then
839
-
if(m.slice(-1)===".")
846
+
if(m.slice(-1)==="."){
840
847
// a. Remove the last character from m.
841
848
m=m.slice(0,-1);
842
-
843
-
letz;
849
+
}
844
850
// 9. If int < minInteger, then
845
-
if(igr<minInteger)
846
-
// a. Let z be the String consisting of minInteger–int occurrences of the
847
-
// character "0".
848
-
z=arrJoin.call(Array(minInteger-igr+1),'0');
849
-
850
-
// 10. Let m be the concatenation of Strings z and m.
851
-
// 11. Return m.
852
-
return(z ? z : '')+m;
851
+
if(int<minInteger){
852
+
// a. Let z be the String consisting of minInteger–int occurrences of the character "0".
853
+
letz=arrJoin.call(Array(minInteger-int+1),'0');
854
+
// a. Let m be the concatenation of Strings z and m.
0 commit comments