$values = array_column($array2, 'value');
$result = array_filter($array1, fn($n) => in_array($n->code, $values));
const result = array2.filter(function(n) {
return this.has(n.code);
}, new Set(array1.map(n => n.value)));
const obj2 = Object.fromEntries(array2.map(n => [ n.code, n ]));
const result = array1.reduce((acc, n) => ((n = obj2[n.value]) && acc.push(n), acc), []);
const result = array2.filter(n => array1.some(m => m.value === n.code));
const array1 = [{ value: '0E1' }, { value: '8B3' }];
const array2 = [
{ code: '0E1', desc: 'Some text' },
{ code: '8B3', desc: 'Some text' },
{ code: '9N8', desc: 'Some text' },
];
const filter = array1.map((el) => el.value);
const result = array2.filter((el) => filter.includes(el.code));
console.log(result);
// Array [ {…}, {…} ]
// 0: Object { code: "0E1", desc: "Some text" }
// 1: Object { code: "8B3", desc: "Some text" }
{
type: m.subType === 'warning' ? 'warn' : m.subType
}
{
type: m.subType,
}
const messages = [{
id: 1,
subType: 'warning'
},
{
id: 2,
subType: 'info'
},
{
id: 3,
subType: 'some'
},
];
const newMessages = messages.map(({id, subType}) => ({
explanation: '',
messageid: id,
type: (subType === 'warning') ? 'warn' : (subType === 'info') ? 'info' : 'error'
}));
console.log(newMessages);
// подправил для наглядности
using System;
using System.Linq;
namespace SiO2
{
class Program
{
static void Main(string[] args)
{
var name = "SiO2 (полиморф.)";
var curTemp = 846.15;
var (h, s, a, b, c) = (-1f, -1f, -1f, -1f, -1f);
var names = new string[]
{
"SiO2 (β-кварц)",
"SiO2 (α-кварц)",
"SiO2 (α-тридимит)",
"SiO2 (β-кристобалит)",
"SiO2(к) кварц",
"SiO2(к) тридимит",
"SiO2(к) кристобалит",
"SiO2 (полиморф.)"
};
var values = new (float, float, float, float, float)[]
{
(-217.75F, 10.00F, 11.22F, 8.2F, -2.70F),
(-217.60F, 0.00F, 14.41F, 1.94F, 0.00F),
(-216.50F, 10.40F, 13.64F, 2.64F, 0.00F),
(-215.95F, 10.19F, 4.28F, 21.06F, 0.00F)
};
if (names.Contains(name))
{
if (curTemp <= 846.15)
(h, s, a, b, c) = values[0];
else if (curTemp >= 846.15)
(h, s, a, b, c) = values[1];
else if (curTemp >= 1143.15)
(h, s, a, b, c) = values[2];
else if (curTemp >= 1743.15)
(h, s, a, b, c) = values[3];
}
Console.WriteLine(h);
Console.WriteLine(s);
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
}
}
}