This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function countClasses(array) { | |
var object = {} | |
; | |
array.forEach(function(element) { | |
if (object[element]) { | |
object[element]++; | |
} | |
else { | |
object[element] = 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10] | |
, i | |
, sum | |
; | |
console.time("while"); | |
i = arr.length; | |
sum = 0; | |
while (i--) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function square(a) { | |
return a*a; | |
} | |
function squareMaxElements (a,b,c) { | |
var min = Math.min(a,b,c) | |
, arr = [a,b,c] | |
; | |
return arr = arr.filter(function (element) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[{a:1},{a:undefined},{a:3}].reduce( function(a,b) { | |
if (b.a) { | |
return a+=b.a | |
} | |
else { | |
return a | |
} | |
},0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//function to test | |
function aPlusB (a,b) { | |
return a+b | |
}; | |
//test-function | |
function testAplusB (func) { | |
return func(2,1) === 3 | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createList(array) { | |
var list = createNext(0, array); | |
return list; | |
} | |
function createNext(i, array) { | |
var result; | |
if (i < array.length) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function changeVal (obj, path, val) { | |
var arr = path.split('.'); | |
var object = obj || {}; | |
var tempObj = object; | |
for (var i = 0; i < arr.length - 1; i += 1) { | |
if(typeof tempObj[arr[i]] !== 'object') { | |
tempObj[arr[i]] = {}; | |
} | |
tempObj = tempObj[arr[i]]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function compareTwoObjects (objOne, objTwo) { | |
var property | |
, checker = true | |
; | |
for (property in objTwo) { | |
if (!objOne[property] || objTwo[property] !== objOne[property] ) { | |
checker = false; | |
return checker; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [5,3,2,1,4]; | |
function bSort(arr) { | |
var i,j,temp; | |
for (i = 0; i < arr.length; i += 1) { | |
for (j = i + 1; j < arr.length; j += 1) { | |
if (arr[i] > arr[j]) { | |
temp = arr[i]; | |
arr[i] = arr[j]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = [ | |
{ccy:"EUR", balance:1000}, | |
{ccy:"USD", balance:"2700"}, | |
{ccy:"EUR", balance:"5600"}, | |
{ccy:"USD", balance:"2500"} | |
] | |
var newArr = []; | |
arr.reduce(function(previousValue, currentValue, index, array) { |