Skip to content

New Useful functions - #3

Open
rk-chr wants to merge 13 commits into
developfrom
master
Open

New Useful functions#3
rk-chr wants to merge 13 commits into
developfrom
master

Conversation

@rk-chr

@rk-chr rk-chr commented Sep 17, 2019

Copy link
Copy Markdown

export const MakeArray = (len, val = undefined) => new Array(len).fill(val);
/* example */
const user_output = [{ rating: 2, order_id: 2}, {rating: 4, order_id: 3}];

const queryRatings = [{ rating: 4, order_id: 3}, {rating: 3, order_id: 2}];

for (var i=0; i < queryRatings.length; i++ ) {
for(var j=0;j < user_output.length; j++) {
if(user_output[j].order_id === queryRatings[i].order_id) {
user_output.splice(j, 1);
break;
}
}
}

console.log([...user_output, ...queryRatings]);
/* example */

export const remove_arrOfObj_duplicates = (arrOfobj1, arrOfobj2) => { for (var i=0; i < queryRatings.length; i++ ) { for(var j=0;j < user_output.length; j++) { if(user_output[j].order_id === queryRatings[i].order_id) { user_output.splice(j, 1); break; } } } return [...user_output, ...queryRatings]; }

@coveralls

Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 553

  • 11 of 11 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 22: 0.0%
Covered Lines: 40
Relevant Lines: 40

💛 - Coveralls

@rk-chr rk-chr changed the title Simple function to make array. New Useful functions Oct 21, 2019
@rk-chr

rk-chr commented Oct 21, 2019

Copy link
Copy Markdown
Author

const user_output = [{ rating: 2, order_id: 2}, {rating: 4, order_id: 3}];

const queryRatings = [{ rating: 4, order_id: 3}, {rating: 3, order_id: 2}];

for (var i=0; i < queryRatings.length; i++ ) {
for(var j=0;j < user_output.length; j++) {
if(user_output[j].order_id === queryRatings[i].order_id) {
user_output.splice(j, 1);
break;
}
}
}

console.log([...user_output, ...queryRatings]);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants