Skip to content

Instantly share code, notes, and snippets.

@di3
Last active April 10, 2019 03:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save di3/0ac2405f6d2c539e4cb60889ac467593 to your computer and use it in GitHub Desktop.
Save di3/0ac2405f6d2c539e4cb60889ac467593 to your computer and use it in GitHub Desktop.
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