Comparing a constant with an array(or multiple values.)
Tag : php , By : CrookedNumber
Date : March 29 2020, 07:55 AM
should help you out I am trying to search zipcodes matchin in area of 25 miles. lets say I got 10 zip codes from my function that holds true. , It looks like you're just looking for the IN keyword: SELECT * FROM TABLE_NAME WHERE POSTAL_CODE IN ($zip_res);
$zip_res = "'" . str_replace(',',"','",$zip_res) . "'";
|
How to retrieve multiple values from a string into an array in powershell
Date : March 29 2020, 07:55 AM
I wish this helpful for you I'm looking to find a way to retrieve all of the MX records listed in a string into a text file. , Modify your Select-String like so: ... | Select-String 'MX:\s*([^,]+)' -AllMatches |
Foreach {$_.Matches | Foreach {$_.Value}}
|
Comparing my array works until the array has multiple values in it
Date : March 29 2020, 07:55 AM
I wish did fix the issue. The problem lies in the fact that you're passing an array to String#indexOf() (as in collection[i].innerText.toLowerCase().indexOf(searchText)). That function expects a string as the search term, and not an array. What's happening is that your array is getting converted into a string. When your array contains only a single string and no other elements, it works because its string representation is that same string. But when your array contains more than one element, its string representation is a comma-separated list of all those strings, and that's not going to compare correctly. var postList = document.getElementsByClassName("post");
var userList = new Array();
//compares the user's keyword entries to the text in the divs, and marks "matching" divs with a red background
function listComparison(collection, searchList) {
for (var i = 0; i < searchList.length; i++) {
for (var j = 0; j < collection.length; j++) {
if (collection[j].innerText.toLowerCase().indexOf(searchList[i]) > -1) {
collection[j].style.backgroundColor = "red";
}
}
}
}
//adds user entries to an array on click and clears out the textarea
document.getElementById("save").addEventListener("click", function() {
var listEntry = document.getElementById("listEntries").value;
userList.push(listEntry);
document.getElementById("listEntries").value = "";
console.log(userList);
})
//event listener for the button that runs the collectionContains function above
document.getElementById("run").addEventListener("click", function() {
listComparison(postList, userList);
});
div {
background: #d0dbe6;
margin: 5px;
width: 50%;
}
#list {
width: 300px;
height: 100px;
}
<textarea placeholder="Enter words here one at a time and click 'Add to Filter'" id="listEntries"></textarea>
<br>
<button id="save" for="listEntries">Add to Filter</button>
<button id="run">Run Filter</button>
<div class="post">religion</div>
<div class="post">cats</div>
<div class="post">hotdogs</div>
<div class="post">babies</div>
<div class="post">test me please</div>
<div class="post">filler</div>
<div class="post">lorem ipsum</div>
<div class="post">your mom</div>
<div class="post">religion again</div>
<div class="post">build a wall</div>
<div class="post">no it's becky</div>
<div class="post">anything with religions in it is screwed!</div>
|
Comparing multiple values from two arrays and storing the results in a new array
Date : March 29 2020, 07:55 AM
This might help you I need to go over a sheet, take employees start date and end date which I successfully receive as props, format them in a proper way (different sheets = different date formats), that goes well, but depending on the date clicked I need to display a list of employees that worked in that period, meaning if they stopped working after that particular date, they'll be listed, but if they started after that date, they wouldn't be listed. , THIS WAS THE SOLUTION. NOW I CAN FINALLY GO TO SLEEP :) const result = [];
employees.forEach(emp => {
if (finalSelect > parseInt(moment(emp.startdate).format('YYYYMM')) &&
(finalSelect < parseInt(moment(emp.enddate).format('YYYYMM'))) ||
(parseInt(moment(emp.enddate).format('YYYYMM') !"= 'undefined'))) {
result.push(emp);
}
});
|
Powershell - Get array of non-null values from fields in multiple rows of a PSObject (or multiple JSON array items)?
Date : March 29 2020, 07:55 AM
To fix the issue you can do I have some JSON like this (which came from a PSObject): , This works: $ticketsObject |
ForEach-Object {$_.Psobject.properties |
where-Object {$_.Name -like 'cf*' -and $_.Value } | select -expand Value}
|