My requirement.EX: date(2019-07-01) in that month 4th week i wanna particular dates based on like["1","6","7"] . ex Result like: [2019-07-28,2019-,2019-08-02,2019-08-03]
var data = {"2020-07-01",
"2020-07-02",
"2020-07-03",
"2020-07-04",
"2020-07-05",
"2020-07-06",
"2020-07-07",
"2020-07-08",
"2020-07-09",
"2020-07-10",
"2020-07-11",
"2020-07-12",
"2020-07-13",
"2020-07-14",
"2020-07-15",
"2020-07-16",
"2020-07-17",
"2020-07-18",
"2020-07-19",
"2020-07-20",
"2020-07-21",
"2020-07-22",
"2020-07-23",
"2020-07-24",
"2020-07-25",
"2020-07-26",
"2020-07-27",
"2020-07-28",
"2020-07-29",
"2020-07-30",
"2020-07-31",}
for(var n = 0; n < data.on.order.length; n++){
for(var m = 0; m < data.on.days.length; m++){
//****
if(data.on.order[n] === '1'){
firstdayMonth = moment(endOfMonth).date(0);
}else{
firstdayMonth = moment(endOfMonth).date(1);
}
// console.log('------------1',firstdayMonth)
var firstdayWeek = moment(firstdayMonth).isoWeekday(parseInt(data.on.days[m],10));
console.log('------------2 ',firstdayWeek)
// if(data.on.order[n] === "1"){
nWeeks = parseInt(data.on.order[n],10);
// }else{
// nWeeks = parseInt(data.on.order[n],10);
// }
var nextEvent = moment(firstdayWeek).add(nWeeks,'w');
// = moment(firstdayWeek).add(nWeeks,'w');
console.log('------------3',nextEvent,'---- ',nWeeks)
//****
if(nextEvent.isAfter(eventDate)){
eventDate = nextEvent;
// console.log("### eventDate: ", eventDate)
// console.log('Total dates in month ',eventDate.format("YYYY-MM-DD"))
meetings.push(eventDate.format("YYYY-MM-DD"));
}
}
}
I need to do a loop in Node JS where I need the result of the previous iteration.
function jsonParser(txt_file, cb) {
var perc = 0;
lines = txt_file.split('\n');
insert_communication = 'INSERT INTO communication (account_id, contact_id, type_com_id, coin_id, com_datetime, ' +
'destination_key, destination_st, duration, cost, description, discount) VALUES ';
insert_internet = 'INSERT INTO internet_data (account_id, contact_id, type_com_id, coin_id, com_datetime, ' +
'duration, cost, description, discount) VALUES ';
for (let i = 2; i < lines.length; i++) {
readTextFile2(lines[i], function (cb) {
if (cb[0] == "communication")
insert_communication += cb[1] + ',';
if (cb[0] == "internet")
insert_internet += cb[1] + ',';
});
}
cb(insert_communication);
}
How I am supposed to achieve this?
Thanks
for (let i = 2; i < lines.length; i++) {
const previous = lines[i - 1 ];
const hasPrevious = !!previous;
if(hasPrevious) {
//ok you have a previously value, now you could use it
}
readTextFile2(lines[i], function (cb) {
if (cb[0] == "communication")
insert_communication += cb[1] + ',';
if (cb[0] == "internet")
insert_internet += cb[1] + ',';
});
}
This is the code to iterate through a dynamic table.
driver.findElements(By.xpath(`//*[#id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr`)).then(function(rows) {
console.log("NoofRowsinthetable" + rows.length);
var identifyvalue = "6/16/17 12:41 PM"
var datacount = 0;
for (var i = 1; i <= rows.length; i++) {
driver.findElements(By.xpath(`//*[#id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[i]/td`)).then(function (cells) {
console.log("NoofColumnsinthetable" + cells.length);
for (var j = 1; j <= cells.length; j++) {
driver.findElement(By.xpath(`//*[#id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[i]/td[j]`)).getText().then(function (cell_text) {
console.log(cell_text);
if (identifyvalue === cell_text) {
datacount = datacount + 1;
console.log("Data count" + datacount);
}
})
First Forloop:
Cells.length returns zero even if there are 9 columns.
IF I AM PASSING THE VALUE OF I AS STRING(tr["+i+"]) THEN IT IS RETURNING THE VALUE OF COLUMN.LENGTH OF FIRST ROW ONLY AND IF I DO NOT PASS THE VALUE OF āIā AS STRING THEN IT IS RETURING THE COLUMN.LENGTH AS ZERO.
Second For loop:
IF I AM PASSING THE VALUE OF I AND J AS STRING(tr["+i+"]/td["+j+"]), THEN IT IS RETURNING THE VALUE OF FIRST COLUMN ONLY
The problem is with single quote. you are starting the string with single quote and it should be ended with single. try the following,
driver.findElements(By.xpath(`//*[#id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr`)).then(function(rows) {
console.log("NoofRowsinthetable" + rows.length);
var identifyvalue = "6/16/17 12:41 PM"
var datacount = 0;
for (var i = 1; i <= rows.length; i++) {
driver.findElements(By.xpath(`//*[#id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[`+i+`]/td`)).then(function (cells) {
console.log("NoofColumnsinthetable" + cells.length);
for (var j = 1; j <= cells.length; j++) {
driver.findElement(By.xpath(`//*[#id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[`+i+`]/td[`+j+`]`)).getText().then(function (cell_text) {
console.log(cell_text);
if (identifyvalue === cell_text) {
datacount = datacount + 1;
console.log("Data count" + datacount);
}
})
Am using Fck editor to write content. Am storing the text as versions in db. I want to highlight those changes in versions when loading the text in FCK Editor.
How to compare the text....
How to show any text that has been deleted in strike through mode.
Please help me/...
Try google's diff-patch algorithm http://code.google.com/p/google-diff-match-patch/
Take both previous and current version of the text and store it into two parameters. Pass the two parameters to the following function.
function diffString(o, n) {
o = o.replace(/<[^<|>]+?>| /gi, '');
n = n.replace(/<[^<|>]+?>| /gi, '');
var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/));
var str = "";
var oSpace = o.match(/\s+/g);
if (oSpace == null) {
oSpace = ["\n"];
} else {
oSpace.push("\n");
}
var nSpace = n.match(/\s+/g);
if (nSpace == null) {
nSpace = ["\n"];
} else {
nSpace.push("\n");
}
if (out.n.length == 0) {
for (var i = 0; i < out.o.length; i++) {
str += '<span style="background-color:#F00;"><del>' + escape(out.o[i]) + oSpace[i] + "</del></span>";
}
} else {
if (out.n[0].text == null) {
for (n = 0; n < out.o.length && out.o[n].text == null; n++) {
str += '<span style="background-color:#F00;"><del>' + escape(out.o[n]) + oSpace[n] + "</del></span>";
}
}
for (var i = 0; i < out.n.length; i++) {
if (out.n[i].text == null) {
str += '<span style="background-color:#0C0;"><ins>' + escape(out.n[i]) + nSpace[i] + "</ins></span>";
} else {
var pre = "";
for (n = out.n[i].row + 1; n < out.o.length && out.o[n].text == null; n++) {
pre += '<span style="background-color:#F00;"><del>' + escape(out.o[n]) + oSpace[n] + "</del></span>";
}
str += " " + out.n[i].text + nSpace[i] + pre;
}
}
}
return str;
}
this returns an html in which new text is marked green and deleted text as red + striked out.
I'm trying to count some variables whit google apps script in google spreadsheet.
This isn't working how I wanted to be.
The code is:
for(var n in namen) {
var naam = namen[n];
var nr = n;
if(w == 1) {
var nr = 3+n;
} if(w == 2) {
var nr = 17+n;
} if(w == 3) {
var nr = 31+n;
} if(w == 4) {
var nr = "45"+n;
} if(naam == title){
ssRooster.getRange(nr, col, 1, 1).setValue(dateStr);
var nr = n;
}
}
Or the code is:
} if(naam == title){
ssRooster.getRange(n+row, col, 1, 1).setValue(dateStr);
}
It should be ok, but I get now The number from n lets say 2 and the number from row lets say 17. It results now as 217 instead of 19. How can I fix this?
Prefer the code with the row in it. (It's cleaner)
Thanks Dennis
[edit]
The compleete code is:
function LoadWorkTime() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var Period = Browser.inputBox("Periode","Welke periode wilt U zien. (kies tussen de 1 en de 12.)", Browser.Buttons.OK);
var ErrorPeriod = "De periode die U invoert is onjuist!";
if(Period>12){
Browser.msgBox(ErrorPeriod);
return;
} if(Period<1){
Browser.msgBox(ErrorPeriod);
return;
}
var ssPeriode = ss.setActiveSheet(ss.getSheets()[1]);
var ThisYear = ssPeriode.getRange(2, 1, 1, 1).getValue();
var CheckYear = Browser.msgBox("Jaar","Is het jaar " + ThisYear + " het jaar dat U wilt opvragen.", Browser.Buttons.YES_NO);
if(CheckYear=="yes") {
var CheckYear = ThisYear;
} else {
var PastYear = ThisYear-1;
var AfterYear = ThisYear-0+1;
var CheckYear = Browser.inputBox("Jaar", "Vul in jaar tal in tussen " + PastYear + " en " + AfterYear, Browser.Buttons.OK);
var ErrorYear = "Het jaar wat U heeft ingevuld is onjuist!";
if(CheckYear>PastYear){
Browser.msgBox(ErrorYear);
return;
} if(CheckYear<AfterYear){
Browser.msgBox(ErrorYear);
return;
}
}
ssPeriode.getRange(1, 1, 1, 1).setValue(Period);
ssPeriode.getRange(3, 1, 1, 1).setValue(CheckYear);
var ssRooster = ss.setActiveSheet(ss.getSheets()[0]);
var calRooster = CalendarApp.getCalendarById("0000#group.calendar.google.com");
var calVakantie = CalendarApp.getCalendarById("0000#group.calendar.google.com");
var dateRow = 2
var row = 3;
for(var w = 1; w <= 4; ++w) {
var col = 2;
var namen = ssRooster.getRange(3, 1, 10, 1).getValues();
for(var d = 1; d <= 7; ++d) {
var eventdate = ssPeriode.getRange(dateRow, 2, 1, 1).getValue();
var eventsRooster = calRooster.getEventsForDay(new Date(eventdate));
var dateRow = dateRow+1;
for(var e in eventsRooster) {
var event = eventsRooster[e];
var title = event.getTitle();
var dateStr = event.getStartTime();
Browser.msgBox(title);
for(var n in namen) {
var naam = namen[n];
Browser.msgBox(naam);
}
if(naam == title){
ssPeriode.getRange(5, 1, 1, 1).setFormula('=' + n + '+' + row);
var nr = ssPeriode.getRange(5, 1, 1, 1).getValue();
ssRooster.getRange(nr, col, 1, 1).setValue(dateStr);
}
}
var col = col+2;
}
var row = row+14;
}
}
I can't make this work! In my eye's is this a good code.
To try it your self run this install code and change the calendar addresses for one you own.
function Install() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var ssPeriode = ss.setActiveSheet(ss.getSheets()[1]);
var Wt = 1;
ssPeriode
ssPeriode.deleteColumns(2, ssPeriode.getMaxColumns()-1);
ssPeriode.deleteRows(2, ssPeriode.getMaxRows()-1);
ssPeriode.clear();
ssPeriode.clearContents();
ssPeriode.clearFormats();
ssPeriode.insertColumnsAfter(1, 1);
ssPeriode.insertRows(1, 35);
ssPeriode.getRange(1, 1, 4, 1).setValues([["1"], [""], ["2012"], ["3-1-2000"]]);
ssPeriode.getRange(2, 1, 1, 1).setFormula('=TEXT(NOW(); "yyyy")');
ssPeriode.getRange(1, 2, 1, 1).setFormula('=A1');
ssPeriode.getRange(2, 2, 1, 1).setFormula('=(A3-2000)*364+((B1-1)*28)+A4');
for(var i = 3; i <= 29; ++i) {
var c = i-1;
ssPeriode.getRange(i, 2, 1, 1).setFormula('=B' + c + '+1');
}
var c = 2;
for(var i = i+1; i <= 34; ++i) {
ssPeriode.getRange(i, 1, 1, 1).setFormula('=SPLIT(TEXT(B' + c + ';"yyyy-ww");"-")');
var c = c+7;
}
var ssRooster = ss.setActiveSheet(ss.getSheets()[0]);
var Wt = 1;
var week = 31;
var dag = 2;
var nm = 3;
ssRooster.deleteColumns(2, ssRooster.getMaxColumns()-1);
ssRooster.deleteRows(2, ssRooster.getMaxRows()-1);
ssRooster.clear();
ssRooster.clearContents();
ssRooster.clearFormats();
ssRooster.insertColumnsAfter(1, 14);
ssRooster.insertRows(1, 56);
for(var col = 1; col <= ssRooster.getMaxColumns(); ++col) {
ssRooster.setColumnWidth(col, 60);
if(col == 1) {
ssRooster.setColumnWidth(col, 80);
}
}
for(var i = 1; i <= 4; ++i) {
ssRooster.getRange(Wt, 1, 13, 15).setBorder(true, true, true, true, false, false);
ssRooster.getRange(Wt, 1, 2, 15).setBorder(true, true, true, true, false, false);
ssRooster.getRange(Wt+2, 1, 11).setNumberFormat("H:mm")
ssRooster.getRange(Wt, 1, 1, 1).setFormula('=JOIN(P1;"Week ";P1;Periode!B' + week + ')');
var week = week+1;
var col = 2;
for(var j = 1; j <= 7; ++j) {
ssRooster.getRange(Wt, col, 2, 2).setBorder(true, true, true, true, false, false);
ssRooster.getRange(Wt+2, col, 11, 2).setBorder(true, true, true, true, false, false);
ssRooster.getRange(Wt, col, 1, 2).merge();
ssRooster.getRange(Wt, col, 1, 1).setFormula('=CHOOSE(WEEKDAY(Periode!B' + dag + ';2);"Maandag ";"Dinsdag ";"Woensdag ";"Donderdag ";"Vrijdag ";"Zaterdag ";"Zondag ")&DAY(Periode!B' + dag + ')&CHOOSE(MONTH(Periode!B' + dag + ');" jan";" feb";" mrt";" apr";" mei";" jun";" jul";" aug";" sep";" okt";" nov";" dec")');
var dag = dag+1;
var col = col+2;
}
var Wt = Wt+1;
ssRooster.getRange(Wt, 1, 1, 15).setValues([["Naam", "van", "tot", "van", "tot", "van", "tot", "van", "tot", "van", "tot", "van", "tot", "van", "tot"]]);
for(var k = 1; k <= 6; ++k) {
var Wt = Wt+1;
ssRooster.getRange(Wt, 1, 1, 15).setBackground('yellow');
var Wt = Wt+1;
}
var Wt = Wt-12;
if( i == 1) {
var Wt = Wt+13;
}
if( i >= 2) {
for(var k = 1; k <= 11; ++k) {
var Wt = Wt+1;
ssRooster.getRange(Wt, 1, 1, 1).setFormula('=A' + nm);
var nm = nm+1;
}
var Wt = Wt+1;
ssRooster.getRange(Wt, 1, 1, 15).setBorder(true, false, true, false, false, false);
var Wt = Wt+1;
var nm = nm+3;
}
}
ssRooster.getRange(Wt, 1, 1, 15).clearFormat();
}
You can also use var nr = new Number(n); to make sure that nr is an integer.
I am not sure if I understand but I think the solution is to insure nr is an integer:
var nr = parseInt(n);
and do not use quotes in var nr = "45"+n;
I now write the numbers to a cell and let a third cell count it and call that one up.
In the code is now up and running and in the old code need some modification to let it work.
Everything works now fine.