Skip to content

Instantly share code, notes, and snippets.

@aMoRRoMa
Created August 15, 2017 12:31
Show Gist options
  • Save aMoRRoMa/392e794eb895437d047cbbe6e0b1ebb5 to your computer and use it in GitHub Desktop.
Save aMoRRoMa/392e794eb895437d047cbbe6e0b1ebb5 to your computer and use it in GitHub Desktop.
reduce tests
// начальные тесты
var array = [1, 2, 3];
var result = array.reduce2(function (memo, item) {
return item + memo;
});
console.log(result == 6);
var array = [1, 2, 3];
var result = array.reduce2(function (memo, item) {
memo.push({a: item});
return memo;
}, []);
console.log(result); //[{a:1}, {a:2}, {a:3}]
var array = [1, 2, 3];
var result = array.reduce2(function (memo, item) {
return memo.concat(item);
}, "");
console.log(result == "123");
var array = [1, 2, 3];
var result = array.reduce2(function (memo, item) {
return memo.concat(item*2);
}, "");
console.log(result == "246");
// проверочные тесты
var array = [1];
var result = array.reduce2(function (memo, item) {
return memo + item*2;
});
console.log(result === 1);
var array = [1, 2, undefined, 3];
var result = array.reduce2(function (memo, item) {
return memo + item;
});
console.log(isNaN(result));
var array = [1, 2, null, 3];
var result = array.reduce2(function (memo, item) {
return memo + item;
});
console.log(result === 6);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment