Hello fellow programmers! I'm diving into Javascript and facing a little challenge that I need help with.
Let me share some data that I'm dealing with:
<pre>
[
[
{
"id": 2759178563,
"title": "Ergonomic Paper Computer",
"handle": "ergonomic-paper-computer",
"body_html": "Enable turn-key infrastructures",
...
]
],
...
]
</pre>
Now, let's take a look at the code snippet I have so far:
import { Injectable } from '@angular/core';
...
@Injectable()
export class ShopifyService {
constructor (
private http: Http
) {}
// Methods to fetch, extract, handle data
public findProducts(archetypes) {
return this.fetchProducts().then(
products => {
var result = [],
fetchedResponse = [];
for (var i = 0; i < archetypes.length; i++) {
...
}
return result;
},
error => this.errorMessage = <any>error
)
}
...
public findSingleProductVariant() {
var result = [];
...
return result;
}
}
I've managed to organize my data into arrays of two-dimensional arrays, categorizing them by type. Each category contains multiple variants. Now, I need to enhance my findSingleProductVariant
method to filter out unique pairs of computer and keyboard variants, calculate their prices, and ensure they are not repeated. The condition is that the total price should be less than 1000 before moving on to new pairs. How can I achieve this logic efficiently?