i have an exercise to do :
DELETE A LIST DOUBLOONS
Create a variable of type Object: var myObject = {} or var myObject = new Object ()
Using the Service SpreadsheetApp, get the list of fruits.
Fasten the 2 dimensional array and returned, create a new entry in your object for each new fruit.
If a fruit has already been listed, increment of 1, the counter value to this fruit.
Examples of structures for myObject: myObject = { "Apple": 1, "Pear: 4 ...dropoff Window }dropoff window
After completing all the fruit, buckle to myObject to build a data range with 2 columns (fruit, number of occurrences in the list) and display the result in columns D and E.
indication: use the test: if (myFruit in myObject) {} to test if the result has already been listed or not.
this is the spreadsheet :
http://i.stack.imgur.com/DV4E1.png
the result have to be like this :
http://i.stack.imgur.com/rqDFG.png
and this my code i'm blocked i don't what to do now please help me
//VARIABLE GLOBALE : DECLARATION DES FEUILLES
var ui = SpreadsheetApp.getUi();
var mySpread = SpreadsheetApp.getActiveSpreadsheet();
// AJOUTE UN MENU PERSONNALIÉ DANS LA SPREADSHEET
function onOpen(e) {
ui.createMenu('Third-Step')
.addItem('Del duplicates', 'deldup')
.addToUi();
}
//SUPPRIMER LES DOUBLONS D’UNE LISTE
function deldup() {
var sheet = SpreadsheetApp.getActiveSheet();
var result = [];
if (sheet != null){
var myFruit = sheet.getRange(1, 1, sheet.getLastRow(), 3).getValues();
sheet.getRange(1, 4, sheet.getLastRow() - 1, 2).clearContent()
var i =0;
var myObject = {
"Pomme":[i],
"Poire":[i],
"Banane":[i],
"Pêche":[i],
"Carotte":[i]
};
for (var i=0; i< myObject.length; i++){
if(myFruit in myObject){
i += 1;
}
result.push(myObject);
}
sheet.getRange(1, 4, result.length, result[0].length).setValues(result);
}
else {
sheet.toast("The Sheet is empty !!")
}
}