zoukankan      html  css  js  c++  java
  • js 中的算术运算

    Math.pow(2,53)      // => 9007199254740992: 2 的 53次幂  
    Math.round(.6)      // => 1.0: 四舍五入  
    Math.ceil(.6)       // => 1.0: 向上求整  
    Math.floor(.6)      // => 0.0: 向下求整  
    Math.abs(-5)            // => 5: 求绝对值  
    Math.max(x,y,z)         // 返回最大值  
    Math.min(x,y,z)         // 返回最小值  
    Math.random()       // 生成一个大于等于0小于1.0的伪随机数  
    Math.PI             // π: 圆周率  
    Math.E              // e: 自然对数的底数  
    Math.sqrt(3)            // 3的平方根  
    Math.pow(3, 1/3)        // 3的立方根  
    Math.sin(0)             // 三角函数: 还有Math.cos, Math.atan等  
    Math.log(10)            // 10的自然对数  
    Math.log(100)/Math.LN10     // 以10为底100的对数  
    Math.log(512)/Math.LN2  // 以2为底512的对数  
    Math.exp(3)             // e的三次幂 
    

     js 日期和时间 

    var then = new Date(2011, 0, 1); // 2011年1月1日  
    var later = new Date(2011, 0, 1, 17, 10, 30);// 同一天, 当地时间5:10:30pm,  
    var now = new Date(); // 当前日期和时间  
    var elapsed = now - then; // 日期减法:计算时间间隔的毫秒数  
    later.getFullYear() // => 2011  
    later.getMonth() // => 0: 从0开始计数的月份  
    later.getDate() // => 1: 从1开始计数的天数  
    later.getDay() // => 5: 得到星期几, 0代表星期日,5代表星期一  
    later.getHours() // => 当地时间17: 5pm  
    later.getUTCHours() // 使用UTC表示小时的时间,基于时区 
    

    js 字符串处理  

    var s = "hello, world"  // 定义一个字符串  
    s.charAt(0)             // => "h": 第一个字符  
    s.charAt(s.length-1)        // => "d": 最后一个字符  
    s.substring(1,4)        // => "ell":第2~4个字符  
    s.slice(1,4)            // => "ell": 同上  
    s.slice(-3)             // => "rld": 最后三个字符  
    s.indexOf("l")      // => 2: 字符l首次出现的位置  
    s.lastIndexOf("l")      // => 10:字符l最后一次出现的位置  
    s.indexOf("l", 3)       // => 3:在位置3及之后首次出现字符l的位置  
    s.split(", ")       // => ["hello", "world"] 分割成子串  
    s.replace("h", "H")         // => "Hello, world": 全文字符替换  
    s.toUpperCase()  
  • 相关阅读:
    Hoppz板子
    [cf] Invoking the Magic
    [acm]关于字符的处理
    [acm]排序总结
    [acm]循环队列(不是自己写queue)
    [acm]关于map的一些知识
    [acm]二进制枚举
    P1005 矩阵取数游戏 区间DP
    ICPC North Central NA Contest 2017 (部分)
    灾后重建 弗洛伊德最短路
  • 原文地址:https://www.cnblogs.com/wanghk/p/2891510.html
Copyright © 2011-2022 走看看