Skip to main content
Code Review

Return to Question

added 166 characters in body
Source Link

As the question already says, my code returns a list with the index's that don't exist inside another list.

For this I currently create two lists joining the objects of each index, then filter the values not found and finally I do a loop searching in which index I will find this value within the initial list:

function notfind() {
 const history = [['a','b'],['c','d']]
 const history_join = [];
 var i=0;
 var max = history.length;
 for(i; i<max; i++){
 history_join.push(history[i][0] + history[i][1]);
 }
 
 const new_values = [['c','d'],['e','f']]
 const new_values_join = [];
 var i=0;
 var max = new_values.length;
 for(i; i<max; i++){
 new_values_join.push([new_values[i][0] + new_values[i][1]]);
 }
 const not_match = new_values_join.filter(x => !history_join.includes(x[0]));
 
 var not_contains = [];
 var i=0;
 var max = new_values_join.length;
 for(i; i<max; i++) {
 if (not_match.includes(new_values_join[i])) {
 not_contains.push(new_values[i])
 }
 }
 console.log(not_contains);
}

Output:

[['e','f']]

I would like a review of the method to improve the execution time and number of tasks until reaching the desired result.


Additional information of a method security flaw found by @DaveMeehan:

What if history was [‘a’,’b’] and new values was [‘ab’,’’]

As the question already says, my code returns a list with the index's that don't exist inside another list.

For this I currently create two lists joining the objects of each index, then filter the values not found and finally I do a loop searching in which index I will find this value within the initial list:

function notfind() {
 const history = [['a','b'],['c','d']]
 const history_join = [];
 var i=0;
 var max = history.length;
 for(i; i<max; i++){
 history_join.push(history[i][0] + history[i][1]);
 }
 
 const new_values = [['c','d'],['e','f']]
 const new_values_join = [];
 var i=0;
 var max = new_values.length;
 for(i; i<max; i++){
 new_values_join.push([new_values[i][0] + new_values[i][1]]);
 }
 const not_match = new_values_join.filter(x => !history_join.includes(x[0]));
 
 var not_contains = [];
 var i=0;
 var max = new_values_join.length;
 for(i; i<max; i++) {
 if (not_match.includes(new_values_join[i])) {
 not_contains.push(new_values[i])
 }
 }
 console.log(not_contains);
}

Output:

[['e','f']]

I would like a review of the method to improve the execution time and number of tasks until reaching the desired result.

As the question already says, my code returns a list with the index's that don't exist inside another list.

For this I currently create two lists joining the objects of each index, then filter the values not found and finally I do a loop searching in which index I will find this value within the initial list:

function notfind() {
 const history = [['a','b'],['c','d']]
 const history_join = [];
 var i=0;
 var max = history.length;
 for(i; i<max; i++){
 history_join.push(history[i][0] + history[i][1]);
 }
 
 const new_values = [['c','d'],['e','f']]
 const new_values_join = [];
 var i=0;
 var max = new_values.length;
 for(i; i<max; i++){
 new_values_join.push([new_values[i][0] + new_values[i][1]]);
 }
 const not_match = new_values_join.filter(x => !history_join.includes(x[0]));
 
 var not_contains = [];
 var i=0;
 var max = new_values_join.length;
 for(i; i<max; i++) {
 if (not_match.includes(new_values_join[i])) {
 not_contains.push(new_values[i])
 }
 }
 console.log(not_contains);
}

Output:

[['e','f']]

I would like a review of the method to improve the execution time and number of tasks until reaching the desired result.


Additional information of a method security flaw found by @DaveMeehan:

What if history was [‘a’,’b’] and new values was [‘ab’,’’]

Source Link

List with values not found in another list when each index has two objects

As the question already says, my code returns a list with the index's that don't exist inside another list.

For this I currently create two lists joining the objects of each index, then filter the values not found and finally I do a loop searching in which index I will find this value within the initial list:

function notfind() {
 const history = [['a','b'],['c','d']]
 const history_join = [];
 var i=0;
 var max = history.length;
 for(i; i<max; i++){
 history_join.push(history[i][0] + history[i][1]);
 }
 
 const new_values = [['c','d'],['e','f']]
 const new_values_join = [];
 var i=0;
 var max = new_values.length;
 for(i; i<max; i++){
 new_values_join.push([new_values[i][0] + new_values[i][1]]);
 }
 const not_match = new_values_join.filter(x => !history_join.includes(x[0]));
 
 var not_contains = [];
 var i=0;
 var max = new_values_join.length;
 for(i; i<max; i++) {
 if (not_match.includes(new_values_join[i])) {
 not_contains.push(new_values[i])
 }
 }
 console.log(not_contains);
}

Output:

[['e','f']]

I would like a review of the method to improve the execution time and number of tasks until reaching the desired result.

lang-js

AltStyle によって変換されたページ (->オリジナル) /