Last active
May 31, 2019 02:33
-
-
Save islishude/a5246402d58b160877e9487a24211b04 to your computer and use it in GitHub Desktop.
paginate.js
This file contains 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
const json = { | |
BTC: { | |
name: "Bitcoin", | |
symbol: "BTC", | |
image: "https://shapeshift.io/images/coins/bitcoin.png", | |
imageSmall: "https://shapeshift.io/images/coins-sm/bitcoin.png", | |
status: "available" | |
}, | |
"1ST": { | |
name: "FirstBlood", | |
symbol: "1ST", | |
image: "https://shapeshift.io/images/coins/firstblood.png", | |
imageSmall: "https://shapeshift.io/images/coins-sm/firstblood.png", | |
status: "available" | |
}, | |
ANT: { | |
name: "Aragon", | |
symbol: "ANT", | |
image: "https://shapeshift.io/images/coins/aragon.png", | |
imageSmall: "https://shapeshift.io/images/coins-sm/aragon.png", | |
status: "available" | |
} | |
}; | |
function paging(src, per) { | |
const res = []; | |
const page = Math.ceil(src.length / per); | |
for (const i = 0, j = 0; j < page; i = i + per, j++) { | |
const tmp = src.slice(i, i + per); | |
res.push(tmp); | |
} | |
return { | |
paginate: res, | |
pageCount: page | |
}; | |
} | |
function json2Array(src) { | |
// Browser did JSON.parse() after AJAX done | |
const keys = Object.keys(src) | |
const res = [] | |
const len = keys.length | |
for (let i = 0; i < len; i++) { | |
let tmp = {} | |
let key = keys[i] | |
tmp[key] = src[key] | |
res.push(tmp) | |
} | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment