zoukankan      html  css  js  c++  java
  • buf.compare()

    buf.compare(otherBuffer)

    • otherBuffer {Buffer}
    • 返回:{Number}
    比较两个 Buffer 实例,无论 buf 在排序上靠前、靠后甚至与 otherBuffer 相同都会返回一个数字标识。比较是基于在每个 Buffer 的实际字节序列。
    • 如果 otherBuffer 和 buf 相同,则返回 0
    • 如果 otherBuffer 排在 buf 前面,则返回 1
    • 如果 otherBuffer 排在 buf 后面,则返回 -1
    ``` const buf1 = Buffer.from('ABC'); const buf2 = Buffer.from('BCD'); const buf3 = Buffer.from('ABCD');

    console.log(buf1.compare(buf1));
    // Prints: 0
    console.log(buf1.compare(buf2));
    // Prints: -1
    console.log(buf1.compare(buf3));
    // Prints: 1
    console.log(buf2.compare(buf1));
    // Prints: 1
    console.log(buf2.compare(buf3));
    // Prints: 1

    [buf1, buf2, buf3].sort(Buffer.compare);
    // produces sort order [buf1, buf3, buf2]

  • 相关阅读:
    day_07 深浅拷贝
    day_06 再谈编码
    day_05 字典
    day_04 列表
    day_03 字符串
    HDU 1049 Climbing Worm
    HDU 1720 A+B Coming
    Pascal向C++的跨越
    B-Boxes
    喵哈哈村的狼人杀大战(4)
  • 原文地址:https://www.cnblogs.com/lalalagq/p/9908612.html
Copyright © 2011-2022 走看看