/**
* Format numbers into 1K, 5M, etc...
* @param n - number to be rouded and formatter
* @param decimal - decimal digits count
* @returns rounded and formatter value.
* @example
* formatCompact(1000) // 1K
* formatCompact(1958) // 2K
* formatCompact(1499) // 1K
* formatCompact(30056456345) // 30B
* formatCompact(1958, 2) // 1.96K
*/
export const formatCompact = (n: number, decimal: number = 0): string => {
if (n === 0) {
return n.toFixed(decimal);
}
const notations = ["", "K", "M", "B", "T", "P", "E", "Z", "Y"];
const id = Math.floor(Math.log(n) / Math.log(1000));
if (id < 0) {
return n.toString();
}
return `${parseFloat((n / Math.pow(1000, id)).toFixed(decimal))}${
notations[id]
}`;
};
class User {
public string id;
public string name;
}
public class Program
{
public static T Request<T>(string url) where T : new() {
return new T();
}
public static void Main()
{
var user = Request<User>("https://127.0.0.1");
}
}
<label for="switch">Toggle</label>
Но что делать, если элементов много?
const arr = [1,2,3,4,5,6,7,8,9,10];
arr.forEach((value, index) => {
window[`elem_${index}`] = value;
})
console.log(elem_1); // 1
console.log(elem_2); // 2
const hash = async (str) => {
const msgUint8 = new TextEncoder().encode(str);
const hashBuffer = await crypto.subtle.digest("SHA-512", msgUint8);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, "0")).join("");
return hashHex;
}
Как заставить работать звук WebRTC в Google Chrome?