JSFiddle - React, Tailwind, and code Playground
by Yaroslav Samardak
JavaScript 1.7
const values = [
[12345, 67890],
[23456, 78901],
[0, 0],
[34567, 89012],
]
function reverseString(value) {
return (value === '') ? '' : reverseString(value.substr(1)) + value.charAt(0)
}
function justReverse(index, count) {
/*
1 | --> | 8 --> |
2 | <-- | 9 <-- |
3 | --> | 10 --> |
4 | <-- | 11 <-- |
5 | --> | 12 --> |
6 | <-- | 13 <-- |
7 | --> | 14 --> |
*/
return index < count ? index % 2 !== 0 : index % 2 === 0
}
function safeValue(value, index) {
let out = ''
if (value === undefined) {
out = '-----'
} else if (Number.isInteger(value)) {
out = value + ''
} else {
out = value.toFixed(2)
}
if (out.length > 5 && !(out.length === 6 && out.indexOf('.') !== -1)) out = '-----'
while (out.length < 5 || (out.length < 6 && out.indexOf('.') !== -1)) out = ' ' + out
return out
}
const items = []
values.forEach(([buying, sale], index) => {
if (index % 2 === 0) {
items.push(safeValue(buying, 0))
items.push(safeValue(sale, 0))
} else {
items.push(safeValue(sale, 0))
items.push(safeValue(buying, 0))
}
})
const str = items.join('|')
console.log(str)
/*
const data = []
str.split('').forEach((v) => {
let out = sevenLedFont[10] // Empty
switch (v) {
case ' ': break
case '.':
// tslint:disable-next-line
data[data.length - 1] = data[data.length - 1] | sevenLedFont[12]
return
case '-': out = sevenLedFont[11]; break
default: out = sevenLedFont[Number.parseInt(v, 10)]; break
}
data.push(out)
})
// console.info(str, data.length + 1)
// console.info('E1 ' + data.reverse().map(v => {
// let o = v.toString(16)
// if (o.length < 2) o = '0' + o
// return o
// }).join(' ').toUpperCase())
this.queue.push({
command: SET_CURRENCY_VALUES,
data: Buffer.from(data.reverse())
})
*/