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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Instagram Gallery</title> | |
<script src="https://unpkg.com/[email protected]/dist/vue.min.js"></script> | |
<script src="https://unpkg.com/axios/dist/axios.min.js"></script> | |
<style type="text/css"> | |
:root{ | |
--color: #95e9ef; | |
--background: #1f1f1f; |
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 getRandosFromArray = function(arr, numRandos){ | |
let arrClone = arr.slice(0) | |
let shuffled = shuffle(arrClone) | |
let randos = shuffled.slice(0, numRandos) | |
return randos | |
} | |
// https://bost.ocks.org/mike/shuffle/ | |
const shuffle = function(array) { | |
var m = array.length, t, i; |
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 getRandosFromArray = function(arr, numRandos){ | |
let arrClone = array.slice(0) | |
let shuffled = arrClone.sort(function() { return .5 - Math.random() }) | |
let randos = shuffled.slice(0, numRandos) | |
return randos | |
} |
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 getRandosFromArray = function(arr, numRandos){ | |
let arrClone = arr.slice(0) | |
let randos = [] | |
for (let i = 0; i < numRandos; i++){ | |
let rand = Math.floor(Math.random() * arrClone.length) | |
randos.push(arrClone.splice(rand,1)[0]) // splice returns a new array | |
} | |
return randos | |
} |
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 getRandosFromArray = function(arr, numRandos){ | |
let arrClone = arr.slice(0) | |
let randos = [] | |
for (let i = 0; i < numRandos; i++){ | |
let rand = Math.floor(Math.random() * arrClone.length) | |
randos.push(arrClone.splice(rand,1)) | |
} | |
return randos | |
} |
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
test('getRandosFromArray returns an array of n random items from an array', () => { | |
let array = [{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}, {id: 7}, {id: 8}, {id: 9}] | |
let n = 2 | |
let items = utils.getRandosFromArray(array, n) | |
expect(items.length).toBe(n) | |
expect(array).toContain(items[0]) | |
expect(array).toContain(items[1]) | |
}) |
NewerOlder