function getKeysOfObject() { let o = {'a': 1, 'b': function() {}, 'c': 2}; console.log(Object.keys(o)); } getKeysOfObject(); Result:["a", "b", "c"] ---------------------------------------------------------------------------------------------------------------------------- function addPropertyToObj() { let o = {}; o['a'] = 87; console.log(o); } addPropertyToObj(); Result: {a: 87} ---------------------------------------------------------------------------------------------------------------------------- function processStringWithMap() { let str = 'hello'; let map = Array.prototype.map; let a = map.call(str, function(e) { return e.concat('N')}); console.log(a); } processStringWithMap(); Result: ["hN", "eN", "lN", "lN", "oN"] ---------------------------------------------------------------------------------------------------------------------------- function calculateSumOfNumberArray() { let total = [1,2,3].reduce((accumulator, currentValue)=> {return accumulator + currentValue}); console.log(total); } calculateSumOfNumberArray(); Result: 6 ---------------------------------------------------------------------------------------------------------------------------- function calculateSumOfObjectArray() { let total = [{x:1},{x:2},{x:3}].reduce((accumulator, currentValue) => {return accumulator + currentValue.x},0); console.log(total); } calculateSumOfObjectArray(); Result: 6 ---------------------------------------------------------------------------------------------------------------------------- function flattenArray() { let newArray = [[0,1],[2,3],[4,5]].reduce((accumulator, currentValue)=> {return accumulator.concat(currentValue)},[]); console.log(newArray); } flattenArray(); Result: [0,1,2,3,4,5] ---------------------------------------------------------------------------------------------------------------------------- function countInstancesOfValuesOfArrayInObject() { let names = ['Alice', 'Bob', 'Tiff', 'Bob', 'Alice']; let countedNames = names.reduce((allNames, name)=> { if(name in allNames) { allNames[name]++; } else { allNames[name] = 1; } return allNames; },{}) console.log(countedNames); } countInstancesOfValuesOfArrayInObject(); Result: {Alice: 2, Bob: 2, Tiff: 1} ---------------------------------------------------------------------------------------------------------------------------- function groupBy(objectArray, property) { return objectArray.reduce(function (acc, obj) { let key = obj[property] if (!acc[key]) { acc[key] = [] } acc[key].push(obj) return acc }, {}) } function applyGroup() { let people = [ { name: 'Alice', age: 21 }, { name: 'Max', age: 20 }, { name: 'Jane', age: 20 } ]; let groupedPeople = groupBy(people, 'age'); console.log(groupedPeople); } applyGroup(); Result: { 20: [ { name: 'Max', age: 20 }, { name: 'Jane', age: 20 } ], 21: [{ name: 'Alice', age: 21 }] } ---------------------------------------------------------------------------------------------------------------------------- function removeDuplicatedItem() { let myArray = ['a', 'b', 'a', 'b', 'c', 'e', 'e', 'c', 'd', 'd', 'd', 'd']; let myOrderedArray = myArray.reduce((accumulator, currentValue)=>{ if (accumulator.indexOf(currentValue) === -1) { accumulator.push(currentValue) } return accumulator },[]); return myOrderedArray; } removeDuplicatedItem(); Result: ["a", "b", "c", "e", "d"]