-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution0033.js
45 lines (34 loc) · 1.37 KB
/
solution0033.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
--------------- 8 Kyu - Find the smallest integer in the array ------------------
Instructions:
Given an array of integers your solution should find the smallest integer.
For example:
Given [34, 15, 88, 2] your solution will return 2
Given [34, -345, -1, 100] your solution will return -345
You can assume, for the purpose of this kata, that the supplied array will not be empty.
-------------
Sample Tests
const chai = require("chai");
const assert = chai.assert;
chai.config.truncateThreshold=0;
describe("Smallest Integer Tests", () => {
let sif = new SmallestIntegerFinder();
it("Fixed Tests", () => {
assert.strictEqual(sif.findSmallestInt([78,56,232,12,8]),8,'Should return the smallest int 8');
assert.strictEqual(sif.findSmallestInt([78,56,232,12,18]),12,'Should return the smallest int 12');
assert.strictEqual(sif.findSmallestInt([78,56,232,412,228]),56,'Should return the smallest int 56');
assert.strictEqual(sif.findSmallestInt([78,56,232,12,0]),0,'Should return the smallest int 0');
assert.strictEqual(sif.findSmallestInt([1,56,232,12,8]),1,'Should return the smallest int 1');
});
})
--------------
Psuedo Code:
-use .sort() to arrange in ascending order: .sort(a,b) +>{return a-b})
-return index 0
*/
class SmallestIntegerFinder {
findSmallestInt(args) {
let sorted = args.sort((a, b) => {return a-b});
return sorted[0];
}
}