1// Copyright 2014 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5Array.prototype.getStaggeredFromMiddle = function(i) { 6 if (i >= this.length) { 7 throw("getStaggeredFromMiddle: OOB"); 8 } 9 var middle = Math.floor(this.length / 2); 10 var index = middle + (((i % 2) == 0) ? (i / 2) : (((1 - i) / 2) - 1)); 11 return this[index]; 12} 13 14Array.prototype.contains = function(obj) { 15 var i = this.length; 16 while (i--) { 17 if (this[i] === obj) { 18 return true; 19 } 20 } 21 return false; 22} 23 24Math.alignUp = function(raw, multiple) { 25 return Math.floor((raw + multiple - 1) / multiple) * multiple; 26} 27