Skip to content

Instantly share code, notes, and snippets.

@chaitu87
Last active November 14, 2019 11:48
Show Gist options
  • Save chaitu87/61ac8d077944c665311d0ec1b49bdcc1 to your computer and use it in GitHub Desktop.
Save chaitu87/61ac8d077944c665311d0ec1b49bdcc1 to your computer and use it in GitHub Desktop.
Coding Exercise 14th November
// There are two arrays of Objects
var alist = [{a: 1, b: 2}, {a:3, c:20, d: 5}, {b: 20, a: 15}]
var blist = [{d: 12, c: 10}, {a:3, c:2}, {d: 10, b: 1}]
// PROBLEM #1
// --------------
// Create an array which is a union of alist & blist
// create a new array with objects which contain "a" attribute
// print this array
// PROBLEM #2
// --------------
// Create an array which is a union of alist & blist
// which is sorted by total weight of the attributes
// example: 1st object in alist, {a:1, b: 2} .. total weight is a + b i.e 1+2 = 3
// print this sorted array
// PROBLEM #3
// --------------
// Create an array which is a union of alist & blist
// Give attribute weights
// d: 1
// c: 2
// a: 3
// b: 4
// Sort the union array with sorted by total weight of the attribute.
// example: 1st object in alist, {a:1, b: 2} .. total weight is (1*3) + (4*2) = 3 + 8 = 11
// print this sorted array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment