var t = [1,-1,5,-3,5,7, -1, -8];
//alert(biggestSum(t));
//alert(getSum(t, 0, 2));
function getSum(arr, start, end){
//slice starts at start index, but does not include end index
if(end+1<=arr.length) end=end+1;
var a = arr.slice(start, end);
var sum = 0;
for(var i=0; i<a.length; i++){
sum +=a[i];
}
return sum;
}
function biggestSum(arr){
var biggest = 0;
var start = 0;
var end= 0;
for(var i=0; i<arr.length; i++){
for(var j=i; j<arr.length; j++){
var tempSum = getSum(arr, i, j);
if(biggest<tempSum){
//found a bigger one
biggest = tempSum;
start=i;
end=j;
}
}
}
return arr.slice(start, end+1);
}
function sortArrays(arr1, arr2){
var arr3=[];
var i=0,j=0,k=0;
while(i<arr1.length && j<arr2.length){
if(arr1[i]>arr2[j]) {
arr3[k++] = arr2[j++];
}
else{
arr3[k++] = arr1[i++];
}
}
while(i<arr1.length){
//put the rest in if there is any, one has run out
arr3[k++] = arr1[i++];
}
while(j<arr2.length){
arr3[k++] = arr2[j++];
}
return arr3;
}
function isPalendrome(str){
str = str.replace(/( )|(,)|(')/g, "").toLowerCase();
var reverse = str.split("").reverse().join("");
return str==reverse;
}
console.log(sortArrays([0,1, 1], [0, 3, 4, 5, 9]));
console.log(isPalendrome("Go hang a salami, I'm a lasagna hog"));
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.