Last active
April 10, 2019 03:48
-
-
Save di3/0ac2405f6d2c539e4cb60889ac467593 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const shuffle = (array) => { | |
for (let i = array.length - 1; i > 0; i--) { | |
let rand = Math.floor(Math.random() * (i + 1)); | |
[array[i], array[rand]] = [array[rand], array[i]] | |
} | |
} | |
export const filter = (arr, cb) => { | |
var r = []; | |
for (let i = 0, c = arr.length; i < c; i++) { | |
let value = arr[i]; | |
if (cb.call(cb, value, i, arr)) r.push(value); | |
} | |
return r; | |
} | |
export const find = (arr, cb) => { | |
for (let i = 0, c = arr.length; i < c; i++) { | |
if (cb.call(cb, arr[i], i, arr)) return arr[i]; | |
} | |
}; | |
export const inArray = (prop, array) => array.indexOf(prop) !== -1; | |
export const first = (list) => list[0]; | |
export const last = (list) => list[list.length - 1]; | |
export const max = (data) => Math.max.apply(null, data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment