Last active
April 14, 2018 06:10
-
-
Save paveltar/6c7416c88b8ac6ba4c2d2826a753b093 to your computer and use it in GitHub Desktop.
Plane seats price mapping
This file contains hidden or 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
// row must be [bool, bool, bool] ex: [false,0,1], [0,1,0], [1,true,0] etc... | |
priceMapping = (value, index, array) => { | |
if (value) { | |
if (array[index + 1] || array[index - 1]) { | |
return 200 | |
} | |
return 100; | |
} | |
return 0; | |
} | |
getSeatsPrices = pleaneseats => { | |
return planeseats.map(col => { | |
return col.map(row => { | |
return row.map(priceMapping); | |
}); | |
}); | |
}; | |
//////////// DATA ////////// | |
planeseats = [ | |
// column of 3 seats | |
[ | |
// seats row | |
[true, false, true], | |
[0, 1, 0], | |
[1, false, true] | |
], | |
[ | |
[false, true, true], | |
[1, 0, 0], | |
[0, true, false] | |
], | |
[ | |
[true, true, false], | |
[0, 1, 1], | |
[1, false, false] | |
] | |
]; | |
console.log(getSeatsPrices(planeseats)); | |
// // OUTPUT: | |
// [ [ [ 100, 0, 100 ], [ 0, 100, 0 ], [ 100, 0, 100 ] ], | |
// [ [ 0, 200, 200 ], [ 100, 0, 0 ], [ 0, 100, 0 ] ], | |
// [ [ 200, 200, 0 ], [ 0, 200, 200 ], [ 100, 0, 0 ] ] ] | |
// |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment