Coding Test - Code Signal Intro 3

Add Border

1
2
3
4
5
6
7
8
9
function addBorder(picture) {
var width = picture[0].length + 2

return [
'*'.repeat(width),
...picture.map(line => `*${line}*`),
'*'.repeat(width)
]
}

Are Similar

1
2
3
4
5
function areSimilar(a,b){
const aDiff = a.filter((v,i) => v != b[i])
const bDiff = b.filter((v,i) => v != a[i])
return aDiff.length == 0 || aDiff.length == 2 && aDiff.join('') == bDiff.reverse().join('')
}