| const createTypedArray = (function () { |
| function createRegularArray(type, len) { |
| var i = 0; |
| var arr = []; |
| var value; |
| switch (type) { |
| case 'int16': |
| case 'uint8c': |
| value = 1; |
| break; |
| default: |
| value = 1.1; |
| break; |
| } |
| for (i = 0; i < len; i += 1) { |
| arr.push(value); |
| } |
| return arr; |
| } |
| function createTypedArrayFactory(type, len) { |
| if (type === 'float32') { |
| return new Float32Array(len); |
| } if (type === 'int16') { |
| return new Int16Array(len); |
| } if (type === 'uint8c') { |
| return new Uint8ClampedArray(len); |
| } |
| return createRegularArray(type, len); |
| } |
| if (typeof Uint8ClampedArray === 'function' && typeof Float32Array === 'function') { |
| return createTypedArrayFactory; |
| } |
| return createRegularArray; |
| }()); |
| |
| function createSizedArray(len) { |
| return Array.apply(null, { length: len }); |
| } |
| |
| export { |
| createTypedArray, |
| createSizedArray, |
| }; |