Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function(){
- /*
- Inputs need a comma in between each value don't put quotations (line break is allowed)
- Example inputs
- A,
- B,
- C
- */
- //When submit
- $(".submit-values").on('click', function(){
- //get the value in the textarea
- var todayValues = $(".today-input textarea").val();
- var yesterdayValues = $(".yesterday-input textarea").val();
- //remove linebreaks from the inputs
- todayValues = todayValues.replace(/(\r\n|\n|\r)/gm,"");
- yesterdayValues = yesterdayValues.replace(/(\r\n|\n|\r)/gm,"");
- //change the string into array
- var today = todayValues.split(",");
- var yesterday = yesterdayValues.split(",");
- //find the duplicates
- var outputTrue = dupOutput(today, yesterday);
- //find ones not duplicated
- var outputFalse = today.filter(function(val) {
- return outputTrue.indexOf(val) == -1;
- });
- //join the arrays by adding <br> then use html output
- outputTrue = outputTrue.join("<br>");
- outputFalse = outputFalse.join("<br>");
- //display the outputs
- $(".dup .display").html(outputTrue);
- $(".not-dup .display").html(outputFalse);
- //returns duplicates in an array
- function dupOutput(today, yesterday){
- var output = [];
- //loop through today
- for(var i = 0; i < today.length; i++){
- //loop through yesterday if today matches yesterday, push into the output array
- for(var j = 0; j < yesterday.length; j++){
- if(today[i] == yesterday[j]){
- output.push(today[i]);
- }
- }
- }
- return output;
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement