52 lines
992 B
JavaScript
52 lines
992 B
JavaScript
// example jsdoc syntax
|
|
// // -----------------------------------
|
|
// // Values
|
|
//
|
|
// /**
|
|
// * Get the object type string
|
|
// * @param {any} value
|
|
// * @returns {string}
|
|
// */
|
|
// function getObjectType (value /* :mixed */) /* :string */ {
|
|
// return Object.prototype.toString.call(value)
|
|
// }
|
|
|
|
function flatten(array) {
|
|
const flatten = arr => arr.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), [])
|
|
return flatten(array)
|
|
}
|
|
|
|
function sum(arr) {
|
|
return arr.reduce(function (a, b) {
|
|
return a + b
|
|
})
|
|
}
|
|
|
|
function padStart (arr, len, c) {
|
|
len = len || 8
|
|
c = c || 0
|
|
if (len < arr.length) {
|
|
return false
|
|
}
|
|
let pad = len - arr.length
|
|
for (var i = 0; i < pad; i++) {
|
|
arr.unshift(c)
|
|
}
|
|
return arr
|
|
}
|
|
|
|
function padEnd (arr, len, c) {
|
|
len = len || 8
|
|
c = c || 0
|
|
if (len < arr.length) {
|
|
return false
|
|
}
|
|
let pad = len - arr.length
|
|
for (var i = 0; i < pad; i++) {
|
|
arr.push(c)
|
|
}
|
|
return arr
|
|
}
|
|
|
|
export { flatten, sum, padStart, padEnd }
|