MCPcopy Create free account
hub / github.com/betomoedano/JavaScript-Coding-Interview-Questions / classPhotos

Function classPhotos

greedy/class-photos.js:1–17  ·  view source on GitHub ↗
(redShirtHeights, blueShirtHeights)

Source from the content-addressed store, hash-verified

1function classPhotos(redShirtHeights, blueShirtHeights) {
2 redShirtHeights.sort((a, b) => a - b);
3 blueShirtHeights.sort((a, b) => a - b);
4
5 const shirtColorInFirsRow =
6 redShirtHeights[0] < blueShirtHeights[0] ? "RED" : "BLUE";
7
8 for (let idx = 0; idx < redShirtHeights.length; idx++) {
9 const redShirtHeight = redShirtHeights[idx];
10 const blueShirtHeight = blueShirtHeights[idx];
11
12 if (shirtColorInFirsRow === "RED") {
13 if (redShirtHeight >= blueShirtHeight) return false;
14 } else if (blueShirtHeight >= redShirtHeight) return false;
15 }
16 return true;
17}
18
19module.exports = classPhotos;

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected