Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <script src="https://cdn.jsdelivr.net/npm/@standard-software/parts@10.0.0"></script>
</body>
</html>
 
console.log('parts version is ' + parts.VERSION);
// console.log(parts.merge)
const {
  merge, isUndefined, isArray,
} = parts;
const hira = {
  'dog': 'いぬ',
  'cat': ['ねこ'],
  'human': 'ひと',
}
const kana = {
  'dog': ['イヌ'],
  'cat': ['ネコ', 'ニャンコ'],
}
const kan = {
  'dog': [],
  'cat': '猫',
  'human': '人',
  'car' : '車',
}
const result = merge([hira, kana, kan], (value, target, key) => {
  if (!isArray(value)) {
    value = [value];
  }
  if (isUndefined(target)) {
    return value
  }
  for (const v of value) {
    target.push(v);  
  }
  return target;
});
console.log(result);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers