Consider this 2D array:
[
["x","y","z"]
["m","n","o"]
["p","q","r"]
]
The provided word is :"znm" the desired result should be string : "xyzopq"
Consider this 2D array:
[
["x","y","z"]
["m","n","o"]
["p","q","r"]
]
The provided word is :"znm" the desired result should be string : "xyzopq"
Here is an example of using a function for filtering characters in a multidimensional array:
let arr = [
["a","b","c"],
["d","e","f"],
["g","h","i"]
];
function filterCharacters(arr,word) {
return arr // Return the character list,
.flat(1) // converted into a 1D array,
.filter(e => !word.includes(e)) // filtered to elements not in the word,
.join(''); // joined together in a string.
}
console.log(filterCharacters(arr,"iea"))
It seems unnecessary to store the characters in a 2D array for this task. To efficiently work with them, you should consider using a 1D array instead.
const targetWord = "iea";
const charactersArray = [
["a", "b", "c"],
["d", "e", "f"],
["g", "h", "i"]
];
// Initialize all characters as unused
let unusedCharacters = charactersArray.flat(1);
// Loop through each row of the 2D array
for (let row = 0; row < charactersArray.length; row++) {
// Iterate over each element in the row
for (let col = 0; col < charactersArray[row].length; col++) {
let currentChar = charactersArray[row][col];
if (targetWord.includes(currentChar)) {
// If character is used, remove from unused list
let indexToRemove = unusedCharacters.indexOf(currentChar);
unusedCharacters.splice(indexToRemove, 1);
}
}
}
console.log(unusedCharacters); // Display remaining unused characters
console.log(unusedCharacters.join("")); // Concatenate unused characters
This code snippet checks each character in the 2D array against the word and eliminates it from the list of unused characters if found in the word.
const letters = [
["x","y","z"],
["q","r","s"],
["u","v","w"]
];
console.log(letters.flat(1).filter(char=>/[^szq]/.test(char)).join(''))
Is there a way to change the background-color of a clicked Radio Button so it appears highlighted? For example, when the first choice is clicked, I want it to stand out visually. This is the current UI displaying the choices: https://i.stack.imgur.com/a7 ...
When the region is selected, autocomplete addresses should be displayed. Each time the region changes, the Jquery autocomplete function is called. While I am able to get the correct autocomplete addresses for the current region, I also receive address list ...
Recently, I encountered an issue with my server-side method that is triggered through JSON/Ajax. The method itself functions flawlessly and sends back a list as expected. However, I seem to have made an error in my JavaScript code, leading to the following ...
I am looking for a way to extract substrings from a string that are between two specified regex patterns. Here are a few examples: My $$name$$ is John, my $$surname$$ is Doe -> should return [name, surname] My &&name&& is John, my & ...
Can Windows desktop applications be developed using JavaScript? I know about HTA (HTML Application) programs, but I'm curious if there is a more recent .NET or different solution that allows for integrating the DLL libraries from Visual Studio. ...
My challenge is optimizing a function that saves data on a 2D array and sends it over the internet 50 times per second. To minimize size wastage, I aim to adjust the second dimension of the array based on the number of updates in that fraction of a second. ...
I am completely new to React/JSX and I'm struggling to grasp the logic behind how things function. For instance, <input type="checkbox" checked=true /> results in <input type="checkbox checked />. On the other hand, <inp ...
export class DropDownService { private dockerURL; constructor(private infoService: InfoService){ this.infoService.getVersion().subscribe((URL) => { this.dockerURL = URL; }); // Ensuring the ...
I am attempting to retrieve the phone number and mobile number from an array using jquery. jQuery: var data = $('#PhoneLabel').text(); var array = data.split(', '); $.grep(array, function (item, index) { if (item.charAt(0) === &ap ...
I am attempting to filter a basic JSON file based on a specified date range, with both a start date and an end date. Below is the function I have created for this task: var startDate = new Date("2013-3-25"); var endDate = new Date("2017-3-2 ...
I designed a pair of buttons with a single label below. Both buttons acted as standalone entities. <label for="buttons" class ="val">0</label> <input class="btn btn-primary button1" type="button" ...
I'm attempting to create a notification box similar to this one: https://i.sstatic.net/HIJPJ.png As shown, there is a .gif image positioned at the top that will be hidden once the content loads. Now, I want to insert the following image into a <d ...
Is there a way to clear JavaScript and CSS cache in ASP MVC without having to clear browser history? ...
I have multiple buttons on a single page, and I want the hover effect to be applied to all of them with just one code using jQuery. Please review my code below. $(document).ready(function(){ $('.button').hover(function(){ var bc=$(this ...
Column X contains variables with values in each column j. In this case, only U1, X4, and U2 have values, while the other variables from the list ['B', 'X1', 'X2', 'X3', 'X4', 'X5', 'U1', ...
Is there a method to execute customized code after Knockout has inserted the html into the DOM and completed rendering? This is required in order to bind a nested view model to dynamically generated html code. Perhaps like this: <div data-bind="html: ...
I've integrated dotenv into my cypress project and defined variables in a .env file, as shown here: USER=Admin How can I utilize the env variable USER within my npm scripts? "scripts": { "cypress:open": "npx cypress ope ...
When it comes to browser, different JavaScript files share one scope: a.js: var a=1; //by adding "var", we prevent it from becoming a global variable. b.js: console.log(a) //even though a=1, b.js can still access this variable! In Node.js: a.js .... b ...
I'm struggling to identify the element with the highest even digit in a series of arrays. My current code only deals with positive numbers, completely dismissing any negative values. int main() { int ary1[] = { 123, 456, -7890, 12 }; int ary2[] = ...
Initially, the application functions flawlessly on localhost. However, upon deployment to Vercel, an issue arises when users attempt to log out and the cookies are not clearing as intended with res.clearCookie(). Consequently, even after a page refresh, t ...