github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/compiler/natives/src/bytes/bytes.go (about)

     1  // +build js
     2  
     3  package bytes
     4  
     5  func IndexByte(s []byte, c byte) int {
     6  	for i, b := range s {
     7  		if b == c {
     8  			return i
     9  		}
    10  	}
    11  	return -1
    12  }
    13  
    14  func Equal(a, b []byte) bool {
    15  	if len(a) != len(b) {
    16  		return false
    17  	}
    18  	for i, c := range a {
    19  		if c != b[i] {
    20  			return false
    21  		}
    22  	}
    23  	return true
    24  }
    25  
    26  func Compare(a, b []byte) int {
    27  	for i, ca := range a {
    28  		if i >= len(b) {
    29  			return 1
    30  		}
    31  		cb := b[i]
    32  		if ca < cb {
    33  			return -1
    34  		}
    35  		if ca > cb {
    36  			return 1
    37  		}
    38  	}
    39  	if len(a) < len(b) {
    40  		return -1
    41  	}
    42  	return 0
    43  }