Javascript coding for captivate
I have an adobe captivate slide in which there are four buttons. Each button is associated with an array. When button is clicked, the array is displayed. When two buttons are clicked, the arrays get concatenated. I have done everything what I need, but I got stuck with the sorting. The array displayed needs to be sorted in alphabetical order (even if two arrays got concatenated). The array should also get de-duplicated.
I have tried with code below.(JS associated with slide)
var someThings = [ ];
var selected = [ ];
var b_or_v =["bet-vet","bat-vat","reb-rev","bick-vic","ban-van"];
var b_or_p =["back-pack","bet-pet","bit-pit","ban-pan","bin-pin"];
var I_or_e =["bit-bet","pit-pet","sit-set","rib-reb","pick-peck","pin-pen","rip-rep"];
var e_or_a =["bet-bat","set-sat","vet-vat","peck-pack","pet-pat","pen-pan","rep-rap"];
function getUnique( arr )
{
var dupes = [ ];
return arr.filter( function( item )
{
return dupes.hasOwnProperty( item ) ? false : ( dupes[ item ] = true );
});
}
function newArray( arr )
{
var temp = [ ];
if ( selected.indexOf( arr ) != -1 )
{
selected.splice( selected.indexOf( arr ), 1 );
for ( var i = 0; i < selected.length; i++ )
{
temp = temp.concat( selected[ i ] ).sort();
}
someThings = temp;
}
else
{
selected[ selected.length ] = arr+20;
someThings = someThings.concat( arr ).sort();
}
}
function newThings( )
{
var str = getUnique( someThings ).toString();
var res = str.replace( /-/g, ", ");
window.cpAPIInterface.setVariableValue( "things", res );
}
The JS associated with /b/ or /v/ button is
newArray(b_or_v);The JS associated with /b/ or /p/ button is
newArray(b_or_p);The JS associated with /I/ or /e/ button is
newArray(I_or_e);The JS associated with /e/ or /a/ button is
newArray(e_or_a);The JS associated with submit button :
newThings( );
I got perfect result on jsbin.Im unable to do the same in adobe captivate.
JSBin link( for perfect output): JS Bin - Collaborative JavaScript Debugging
It is the slide
