Guest User

Untitled

a guest
Feb 18th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. const pixie = require('pixie')
  2.  
  3. function pixieModel (template, model) {
  4. const result = []
  5. if (template[0].length > template[1].length) {
  6. result[0] = { key: '', value: template[0][0] }
  7. for (let i = template[1].length; i--;) {
  8. let e = i + 1
  9. result[e] = { key: model[template[1][i]], value: template[0][e] }
  10. }
  11. } else {
  12. for (let i = template[1].length; i--;) {
  13. result[i] = { key: model[template[1][i]], value: template[0][i] }
  14. }
  15. }
  16. return result
  17. }
  18.  
  19. const input = '{1}One{2}Two{2}Three{3}Four{1}'
  20. const model = { 1: 'circle', 2: 'check', 3: 'bonus' }
  21. const template = pixie.parse(input, '{', '}')
  22.  
  23. console.log(
  24. pixieModel(template, model)
  25. )
Add Comment
Please, Sign In to add comment