Skip to content

Commit e18831f

Browse files
committed
added iFit questions
1 parent 3540d60 commit e18831f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

codetests/iFit.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
function tripleThreat(a) {
2+
for (const i = 0; i < a.length - 2; i++) {
3+
if ((a[i] + 1 === a[i + 1]) && (a[i + 1] + 1 === a[i + 2])) return 1;
4+
}
5+
return 0;
6+
}
7+
8+
console.log(tripleThreat([0, 4, 5, 6, 10, 12])) // 1
9+
10+
11+
12+
// We need to deliver a package of cookies bags. You will be given an inventory of small bags (1 kilo each) and big bags
13+
// (5 kilos each) along with the goal amount of kilos we need to ship the customer. Return the amount of small bags the package
14+
// will contain assuming we always use big bags first. Return -1 if it cannot be done.
15+
// Input
16+
// small (type: int) - The number of small bags we have to work with
17+
// big (type: int) - The number of big bags we have to work with
18+
// goal (type: int) - The goal weight of the package that we need to ship out
19+
// Output
20+
// In of how many small bags to use, if there isn't enough return -1.
21+
22+
23+
function createPackage(small, big, goal) {
24+
while (goal >= 5 && big > 0) {
25+
goal -= 5;
26+
big--;
27+
}
28+
if (goal > small) {
29+
return -1;
30+
}
31+
return goal;
32+
}
33+
34+
console.log(createPackage(9, 2, 9)); // 4

0 commit comments

Comments
 (0)