function duplicates (arr) { let obj = {}; arr.forEach((str) => { obj[str] = typeof obj[str] === 'undefined' ? false: true; }); return obj; }
function test(arr){ let obj = {}; for(let i = 0; i < arr.length; i++){ let t = arr[i]; !obj.hasOwnProperty(t) ? obj[t] = false : obj[t] = true; } return obj; }
function duplicatedWord(arr) { const result = {}; arr.forEach(d => { if (result[d] === undefined) { result[d] = false; }else if (result[d] === false) { result[d] = true; } }); return result; }
function duplicatedWord( words ){ const res = {} words.forEach( word =>{ if( ! res[word] ){ res[word] = words.indexOf(word) !== words.lastIndexOf(word) } } ) return res }
function dupicaltedWord (names) { return foo = names.reduce((pre, next) => { next in pre ? pre[next] = 'true' : pre[next] = 'false' return pre }, {}) } console.log(dupicaltedWord(names))
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题