Skip to content

New Useful functions #3

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open

New Useful functions #3

wants to merge 13 commits into from

Conversation

rk-chr
Copy link

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

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

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
Copy link
Author

rk-chr commented Oct 21, 2019

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]);

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants