0

I am trying to filter multiple arrays of Skills (they are coming from json file) (example below) and print out the candidate name + all skills

┌─────────┬───────────────────────┐
│ (index) │        Values         │
├─────────┼───────────────────────┤
│    0    │       'angular'       │
│    1    │         'css'         │
│    2    │      'bootstrap'      │
│    3    │      'react.js'       │
│    4    │        'rxjs'         │
│    5    │         'git'         │
│    6    │        'java'         │
│    7    │       'graphql'       │
│    8    │       'node.js'       │
│    9    │        'redux'        │
│   10    │        'json'         │
│   11    │        'html'         │
│   12    │         'sql'         │
│   13    │        'linux'        │
│   14    │      'gatsby.js'      │
│   15    │       'mongodb'       │
│   16    │     'javascript'      │
│   17    │         'php'         │
│   18    │        'ionic'        │
│   19    │ 'amazon web services' │
└─────────┴───────────────────────┘

but instead of all skills I'm just getting single values (1 skill/1 line) and the output looks in console looks like this:

this guys knows javascript
this guys knows nodejs
this guys knows react
this guys knows javascript

But the goal is to have all skills in 1 line like this:

this guys knows javascript nodejs react

input.json

{
    "stackIncluded": [
    "nodejs",
    "javascript"
    ]
}

Here is a code of the function that I've written, index.js

'use strict';
const curationInput = require('./curation-input.json');
const fileToCurate = require('./trlele.json');

async function curateStack() {
  const stackIncluded = curationInput.stackIncluded;
  fileToCurate.forEach(candidate => {
    candidate.folder.forEach(folder => {

      // get Arrays with all objects that including candidates skills
      const allSkills = folder.skills;

      // map Arrays with objects to Arrays with skills only
      const values = allSkills.map(item => item.value);

      // lowercase the values of skills
      const lowercaseSkills = values.map(skill => skill.toLowerCase());
      //console.table(lowercaseSkills)

      lowercaseSkills.forEach(skillsArray => {
        if (stackIncluded.includes(skillsArray)) {
          console.log('this guys knows', skillsArray);
        }
      });

    });
  });
}
2
  • 1
    this guys knows should be before the loop Commented Feb 13, 2021 at 14:14
  • Try creating a string in forEach() candidate where you append each() skill in skills array Commented Feb 13, 2021 at 14:15

1 Answer 1

1

You need to change the last part of your script

let str = 'this guys knows '
lowercaseSkills.forEach(skillsArray => {
    if (stackIncluded.includes(skillsArray)) {
        str += skillsArray + ' ';
    }
});
console.log(str);

another way

const skills = lowercaseSkills.filter(item => stackIncluded.includes(item));
console.log('this guys knows', skills.join(', ')]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.