makeArrayWithoutDuplicates

Run Settings
LanguageJavaScript
Language Version
Run Command
let myArray = ['a', 'b', 'a', 'b', 'c', 'e', 'e', 'c', 'd', 'd', 'd', 'd'] let myArrayWithNoDuplicates = myArray.reduce(function (accumulator, currentValue) { if (accumulator.indexOf(currentValue) === -1) { accumulator.push(currentValue) } return accumulator }, []) console.log(myArrayWithNoDuplicates)
let myArray = ['a', 'b', 'a', 'b', 'c', 'e', 'e', 'c', 'd', 'd', 'd', 'd']; const makeArraysWithoutDuplicate = (array) => { let hashMap = {}; let newArray = []; for (i = 0; i < array.length; i++) { if (!hashMap[array[i]]) { newArray.push(array[i]); } hashMap[array[i]] = array[i]; } return newArray; } console.log(makeArraysWithoutDuplicate(myArray));
const sortArray = (nums) => { const arrayLength = nums.length; for (let i=0; i < arrayLength; i++) { for (let j = 0; j < arrayLength; j++) { if(nums[j] > nums[j+1]) { const temp = nums[j]; nums[j] = nums[j+1]; nums[j+1] = temp; } } } } console.log(sortArray([0,1,2,1,2,2,2,1,0]));
Editor Settings
Theme
Key bindings
Full width
Lines