Write a script which can find indexes & sum of biggest possible sequence subarray items.
Example:
findBiggestSubArray([1, 2, -3, 2])
should return array like [a, b, c]
Where:
a: maximal sum of sequence
b: start index if sequence
c: last index of sequence
More examples:
findBiggestSubArray([1, 1, 1, 1, 1, 1, -5]) ==> return [6, 0, 5]
findBiggestSubArray([-9,1,3,1,1,-6,0,-9]) ==> [6, 1, 4]
findBiggestSubArray([-9,4,-1,5]) ==> [8, 1, 3]
findBiggestSubArray([-9, 4, 1, 1, -9, 5]) ==> [6, 1, 3]
findBiggestSubArray([-9]) ==> [-9, 0, 0]
findBiggestSubArray([-9,8,-2.5,2,1]) ==> [8.5, 1, 4]
function findBiggestSubArray(arr) {
return []
}
describe("Solution", function() {
it("should test for something", function() {
Test.assertDeepEquals(findBiggestSubArray([1, 1, 1, 1, 1, 1, -5]), [6, 0, 5]);
Test.assertDeepEquals(findBiggestSubArray([-9,1,3,1,1,-6,0,-9]), [6, 1, 4]);
Test.assertDeepEquals(findBiggestSubArray([-9,4,-1,5]), [8, 1, 3]);
Test.assertDeepEquals(findBiggestSubArray([-9, 4, 1, 1, -9, 5]), [6, 1, 3]);
Test.assertDeepEquals(findBiggestSubArray([-9]), [-9, 0, 0]);
Test.assertDeepEquals(findBiggestSubArray([-9,8,-2.5,2,1]), [8.5, 1, 4]);
});
});
Create functions thas can sort an array using insertion sort algorithm. Function should return a COPY of sorted array, so the original array wouldn't be mutated
Note: you shouldn't use loops (for/while). Try to complete task in a functional way.
function insertionSort(arr) {
// return sorted array
}
describe("Solution", function() {
it("should test for something", function() {
Test.assertDeepEquals([-1, 0, 1, 2, 3, 5, 6, 9], insertionSort([0, -1, 9, 5, 6, 3, 1, 2]));
Test.assertDeepEquals([], insertionSort([]));
Test.assertDeepEquals([1,2,3], insertionSort([1,2,3]));
Test.assertDeepEquals([0, 0, 1, 1, 1, 9], insertionSort([0, 1, 1, 9, 0, 1]));
Test.assertDeepEquals([4, 100000000, 1000000000000000], insertionSort([1000000000000000, 4, 100000000]));
});
});
// TODO: Create method objectFreeze which works the same as native Object.freeze.
// !IMPORTANT: You haven't use Object.freeze during your task
function objectFreeze(obj) {
return Object.freeze(obj);
}
describe("Solution", function() {
it("should test for something", function() {
const symbol = Symbol()
const obj = objectFreeze({
[symbol]: 10,
x: 20,
y: 30,
_z: 40,
get z() {
return this._z;
},
set z(value) {
this._z = value
},
randomizeX() {this.x = Math.random()}
});
obj.x = 21
Test.assertEquals(obj.x, 20);
obj.z = 41
Test.assertEquals(obj.z, 40);
obj.randomizeX()
Test.assertEquals(obj.x, 20);
obj[symbol] = 11
Test.assertEquals(obj[symbol], 10);
try{
Object.defineProperty(obj, 'y', {value: 31})
Test.fail('Property should be readonly')
} catch(e) {
}
});
});