Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Based on hint solution in Clear category for [old] Non-unique Elements by applecruncher1
"use strict";
let isUnique = (arr,el) => arr.filter(a => a === el).length === 1; //Boolean function to check each number in array if there is a repeat based on input. If only once then input is a unique number
function nonUniqueElements(data) {
return data.filter(item => !isUnique(data,item)); //Filter out items that are unique to the array
}
var assert = require('assert');
if (!global.is_checking) {
assert.deepEqual(nonUniqueElements([1, 2, 3, 1, 3]), [1, 3, 1, 3], "1st example");
assert.deepEqual(nonUniqueElements([1, 2, 3, 4, 5]), [], "2nd example");
assert.deepEqual(nonUniqueElements([5, 5, 5, 5, 5]), [5, 5, 5, 5, 5], "3rd example");
assert.deepEqual(nonUniqueElements([10, 9, 10, 10, 9, 8]), [10, 9, 10, 10, 9], "4th example");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
March 30, 2020