我收到错误 [ERROR] 无法解析项目的 package.json。它是有效的 JSON 文件吗? 但是,我试图将其设置为 JSON 对象,它不接受我的答案。我能做什么?
"rm -rf node_modules/"{
"name": "todo",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "https://ionicframework.com/",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},```
代码应该类似于:
function pairElement(str){
const s = str.split(''), a = [];
s.forEach(v=>{
switch(v.toUpperCase()){
case 'C':
a.push(['C', 'G']);
break;
case 'G':
a.push(['G', 'C']);
break;
case 'A':
a.push(['A', 'T']);
break;
case 'T':
a.push(['T', 'A']);
break;
}
});
return a;
}
const cgc = pairElement('GCG'), ttgag = pairElement('ttgag');
console.log(cgc); console.log(ttgag);
我不知道如何用 forEach() 来做到这一点
function pairElement(str) {
let entriesBasePairs={
A:"T",
T:"A",
C:"G",
G:"C"
}
let newArr=[];
let entriesBase =str.split("");
//Object.entries(entriesBasePairs);
for(let i=0;i<entriesBase.length;i++)
for (let [key, value] of Object.entries(entriesBasePairs)){
if(entriesBase[i]==key){
newArr.push([key, value])
//console.log(`${key}: ${value}`);
}
}
console.log(newArr)
return newArr;
}
pairElement("GCG");