UNPKG

1.81 kBJavaScriptView Raw
1/*
2 * Copyright 2018 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16/** Helper function for formatting ratios as CSS percentage values. */
17export function formatPercentage(ratio) {
18 return "".concat((ratio * 100).toFixed(2), "%");
19}
20/**
21 * Mutates the values array by filling all the values between start and end index (inclusive) with the fill value.
22 */
23export function fillValues(values, startIndex, endIndex, fillValue) {
24 var inc = startIndex < endIndex ? 1 : -1;
25 for (var index = startIndex; index !== endIndex + inc; index += inc) {
26 values[index] = fillValue;
27 }
28}
29/**
30 * Returns the minimum element of an array as determined by comparing the results of calling the arg function on each
31 * element of the array. The function will only be called once per element.
32 */
33export function argMin(values, argFn) {
34 if (values.length === 0) {
35 return undefined;
36 }
37 var minValue = values[0];
38 var minArg = argFn(minValue);
39 for (var index = 1; index < values.length; index++) {
40 var value = values[index];
41 var arg = argFn(value);
42 if (arg < minArg) {
43 minValue = value;
44 minArg = arg;
45 }
46 }
47 return minValue;
48}
49//# sourceMappingURL=sliderUtils.js.map
\No newline at end of file