Skip to content

Instantly share code, notes, and snippets.

function countClasses(array) {
var object = {}
;
array.forEach(function(element) {
if (object[element]) {
object[element]++;
}
else {
object[element] = 1;
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--)
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) {
[{a:1},{a:undefined},{a:3}].reduce( function(a,b) {
if (b.a) {
return a+=b.a
}
else {
return a
}
},0)
@tarzak
tarzak / unitTest.js
Last active September 28, 2015 11:41
example of unit testing from inside?
//function to test
function aPlusB (a,b) {
return a+b
};
//test-function
function testAplusB (func) {
return func(2,1) === 3
};
function createList(array) {
var list = createNext(0, array);
return list;
}
function createNext(i, array) {
var result;
if (i < array.length) {
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]];
function compareTwoObjects (objOne, objTwo) {
var property
, checker = true
;
for (property in objTwo) {
if (!objOne[property] || objTwo[property] !== objOne[property] ) {
checker = false;
return checker;
}
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];
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) {