Skip to content

Instantly share code, notes, and snippets.

@pokorson
Created September 30, 2019 13:10
Show Gist options
  • Save pokorson/2d00f4972bf2d56085d757790d0cbb3d to your computer and use it in GitHub Desktop.
Save pokorson/2d00f4972bf2d56085d757790d0cbb3d to your computer and use it in GitHub Desktop.
JS tasks
// Zadanie 1
const data1 = [1, 2, 3, 4, 4, 2, 1, 3];
console.log([...new Set(data1)]);
// Zadanie 2
const data2 = [{a: 1, b: 2},{a: 5, b: 8},{a: "aaaa", c: "aaaaa"}];
console.log(data2.map(i => i.a));
const data3 = [1, 2, 3, 4];
console.log(data3.map(i => i*2));
const data4 = [1, 2, 3, 4, 5, 6];
console.log(data4.filter(i => i % 2 === 0));
const data5 = [1, 2, 3, 4, 5, 6];
console.log(data5.filter(i => i % 2).reduce((acc, i) => acc + i));
const data6 = {who: "Organization", why: "Harmony", how: "Human"};
console.log(Object.keys(data6).map(key => ({key, value: data6[key] })));
const data7 = [{name: "animal", age: 3},{name: "human", age: 10}]
console.log(
data7.reduce((acc, i) => ({...acc, [i.name]: i.age}), {})
)
const data8 = {key1: 1,key2: "tar",key3: [{name: "animal", age: 3},{name: "human", age: 10}]};
console.log(
Object.keys(data8).map(i => ({key: i, value: data8[i]}))
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment