Javascript for loop to get unique failed -


i'm figuring out how find unique content that's in var test. in var test there's 5 content first row contentid. so, have var contentid show number of used contentid used var test. i'm pushing every content test array , , looping find contentid not being used.

var test = "1#2#did know?#digital rapid! pair of biocarbon engineering drones can plant 100 ,000 trees day.#8#yes\n2#2#did know?#starting summer of 2017, ikea's smart light bulbs answer voice commands given amazon alexa, google assistant, or apple siri. internet of things (iot) revolutionising everyday appliances!#5#unknown\n3#2#did know?#cemex's (a cement company) collaboration platform allows employees share opinions, knowledge, , best practices. ideas every corner of cemex have led new initiatives , business outcomes.#5#unknown\n4#2#did know?#cemex's (a cement company) collaboration platform allows employees share opinions, knowledge, , best practices. ideas every corner of cemex have led new initiatives , business outcomes.#5#unknown\n5#3#did know?#cemex's (a cement company) collaboration platform allows employees share opinions, knowledge, , best practices. ideas every corner of cemex have led new initiatives , business outcomes.#5#unknown\n";    //console.log(test);  var result = [];  var allrows = test.split(/\r?\n|\r/);  var week = '2';  var contentid = '3,2,1';  var splitcontentid = contentid.split(/,/);  var counterloop = splitcontentid.length;  (var singlerow = 0; singlerow < allrows.length; singlerow++) {      var rowcells = allrows[singlerow].split('#');        (var zeus = 0; zeus < counterloop; zeus++) {            if (rowcells[0] == splitcontentid[zeus] && rowcells[1] == week) {              console.log(rowcells[0]);          }      }  }

tldr ; finding unique id that's not being used in var test . used contentid var contentid

jsfiddle :- https://jsfiddle.net/gyp3awja/

can try see if match expectation:

var test = "1#2#did know?#digital rapid! pair of biocarbon engineering drones can plant 100 ,000 trees day.#8#yes\n2#2#did know?#starting summer of 2017, ikea's smart light bulbs answer voice commands given amazon alexa, google assistant, or apple siri. internet of things (iot) revolutionising everyday appliances!#5#unknown\n3#2#did know?#cemex's (a cement company) collaboration platform allows employees share opinions, knowledge, , best practices. ideas every corner of cemex have led new initiatives , business outcomes.#5#unknown\n4#2#did know?#cemex's (a cement company) collaboration platform allows employees share opinions, knowledge, , best practices. ideas every corner of cemex have led new initiatives , business outcomes.#5#unknown\n5#3#did know?#cemex's (a cement company) collaboration platform allows employees share opinions, knowledge, , best practices. ideas every corner of cemex have led new initiatives , business outcomes.#5#unknown\n";  var allrows = test.split(/\r?\n|\r/); var week = '2'; var contentid = '3,2,1'; var splitcontentid = contentid.split(/,/); allrows.foreach(function(row) {     var rowdata = row.split('#');     var rowid = rowdata[0];     var rowweek = rowdata[1];      if (splitcontentid.indexof(rowid) < 0 || rowweek != week) {         console.log(rowid);     } }) 

updated solution


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -