github.com/gopherjs/gopherjs@v1.19.0-beta1.0.20240506212314-27071a8796e4/compiler/natives/src/bytes/bytes.go (about)

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