Skip to content

Instantly share code, notes, and snippets.

@spddl
Created February 26, 2019 12:06
Show Gist options
  • Save spddl/086d83909a7b2ab45ce194fd4eb4b106 to your computer and use it in GitHub Desktop.
Save spddl/086d83909a7b2ab45ce194fd4eb4b106 to your computer and use it in GitHub Desktop.
var a = [1, 2, 3, 4, 5, 6, 7]
var b = ['a', 'b', 'c']
al = a.length
bl = b.length
console.log(al, bl) // 7 3
if (al < bl) {
for (let i = 0, len = (bl - al); i < len; i++) {
a.push('')
}
} else if (al > bl) {
for (let i = 0, len = (al - bl); i < len; i++) {
b.push('')
}
}
console.log(a) // [1, 2, 3, 4, 5, 6, 7]
console.log(b) // ["a", "b", "c", "", "", "", ""]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment